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
分析AIエージェントを育てる、動く環境を育てる
codatum
1
380
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
210
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
130
自主式軟體工廠
philipz
0
240
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
140
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
300
データ品質を壊しながらSnowflakeのAIに分析させてみた
kawanago
0
570
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
500
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
340
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
930
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
17
120k
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
5
1.2k
Featured
See All Featured
Are puppies a ranking factor?
jonoalderson
2
4k
Speed Design
sergeychernyshev
33
2.1k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
560
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Tell your own story through comics
letsgokoyo
1
1.1k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
700
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
470
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
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 のパフォーマンスに物凄いポテンシャルを感じた