Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
luckyframeworkで驚異的なスループットを出した話
Search
y2k2mt
November 02, 2018
Technology
350
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
luckyframeworkで驚異的なスループットを出した話
y2k2mt
November 02, 2018
More Decks by y2k2mt
See All by y2k2mt
Crystal in production
y2k2mt
1
560
Other Decks in Technology
See All in Technology
LLMに渡さなかった仕事
nanaism
0
810
ADKで始める業務改善 - AIエージェント開発時の考えと設計
harappa80
2
200
GoのInterface内部構造から学ぶ!最高パフォーマンスを出すコード設計
yappli_developers
0
160
技術的負債から考える、AI時代のエンジニアリング投資 — ビズリーチの技術的負債と向き合った経験から、変更し続けられるソフトウェアを考える/ technical-debt-con2026
visional_engineering_and_design
4
3.2k
え、こんなに早く改修できるの?──新人エンジニアとスクラムマスターの2人が語る、AI×アジャイル開発の現場
ysasago
2
450
あるけみー式LTスライド作成術
alchemy1115
2
220
映像変換サーバーなしで端末内でHLSを生成してライブ配信
hikarusato
0
130
品質と信頼性を地続きにする
grimoh
1
780
Minecraft JavaのMODをSwiftで作る
1mash0
0
180
Genieを崇めよ
kameitomohiro
0
160
HHKBエバンジェリストになる方法
941
0
110
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
750
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
450
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
320
Documentation Writing (for coders)
carmenintech
77
5.5k
Unsuck your backbone
ammeep
672
58k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
580
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Producing Creativity
orderedlist
PRO
348
41k
What's in a price? How to price your products and services
michaelherold
247
13k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
530
Fireside Chat
paigeccino
43
4k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Transcript
luckyframeworkで驚異的なスループット! @y2k2mt
みなさん、 spider-gazelle という crystal 製のWebフレームワー クをご存知でしょうか? https://github.com/spider‑gazelle
ベンチマークをとると、なんと 300 k req/sec という驚異的なスループ ットを叩き出すというフレームワークです!
なぜこのようなベンチマーク結果を出すことが可能なのかを調べてみま した
spider‑gazelleの実装を見てみると、Webサーバとは別に cluster と いう仕組みが 用意されています https://github.com/spider‑gazelle/action‑ controller/blob/master/src/action‑controller/server.cr#L71
これが何をしているのかというと、動作しているマシンのコア数を取得 して、コア数分の自分自身のプロセスを 立ち上げています count = System.cpu_count if count <= 0
... # Start the processes (0_i64...count).each do @processes << future do process = nil Process.run(process_path, args, input: Process::Redirect::Close, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit )
つまり、1つのcrystal のプロセスが使用できるコアは1つなので、 プロセスをコア数分立ち上げると、全てのコアを使うことが可能になり ます
crystal のHTTPライブラリは SO_REUSEPORT という仕組みに対応てい ます。これは、複数のプロセスで同じポートを使用することを可能にす るTCPソケットのオプションです。(バランシング可能なのはLinux kernel 3.9以降のみ)
crystal での使い方は非常に簡単で、 HTTP::Server の bind_tcp メ ソッドのオプションとして指定するだけです server = HTTP::Server.new
server.bind_tcp("localhost", 5000, reuse_port: true) server.listen
単純にプロセスを並行して立てているだけであれば、 spider- gazelle の仕組みでなくても、 supervisord などで同じことが実行で きるのではないか! ということで、やってみました
crystal の簡単なWebサーバを今回は luckyframework で作ってみ ました。作成したアプリケーションを supervisord で並行して実行す るために のような設定ファイルを書きました [program:bar]
command=/home/foo/bar/server process_name=%(program_name)s_%(process_num)02d numprocs=2 user=foo autorestart=true stdout_logfile=/var/log/supervisor/bar-supervisord.log stdout_logfile_maxbytes=1MB stdout_logfile_backups=5 stdout_capture_maxbytes=1MB redirect_stderr=true
実行! 環境は Ubuntu 16.04 CPU: 4 MEM: 16G (t2‑xlarge) です
numprocs=1 wrk -c20 -t2 http://localhost:5000/heartbeat Running 10s test @ http://localhost:5000/heartbeat 2 threads and 20 connections Thread Stats Avg Stdev Max +/- Stdev Latency 305.35us 71.91us 1.02ms 88.04% Req/Sec 32.61k 1.22k 36.09k 71.78% 655191 requests in 10.10s, 48.74MB read Requests/sec: 64870.08 Transfer/sec: 4.83MB
numprocs=2 Running 1m test @ http://localhost:5000/heartbeat 2 threads and 20
connections Thread Stats Avg Stdev Max +/- Stdev Latency 180.21us 276.69us 8.09ms 96.72% Req/Sec 69.12k 2.84k 76.07k 71.42% 8252187 requests in 1.00m, 613.85MB read Requests/sec: 137515.74 Transfer/sec: 10.23MB
まとめ 並列プロセスを立てて、ポートでバランシグするとCPUを有効活用 できる crystal のパフォーマンスに物凄いポテンシャルを感じた