Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
luckyframeworkで驚異的なスループットを出した話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
550
Other Decks in Technology
See All in Technology
PLaMoを毎日の開発で使い育てていく
pfn
PRO
0
170
テックカンファレンス三大ステークホルダーの文化人類学 ─ 違いを認め合う関係性作り
bash0c7
5
1.6k
コンポーネント名には何を含めるべきなのか? / what-should-be-included-in-component-names
airrnot1106
0
240
もう一度考える SRE チームの作り方・育て方 / Rethinking SRE #1: Building and Growing SRE Teams
rrreeeyyy
4
740
Claude Mythos、Fable...フロンティアAIの最新動向と企業のセキュリティ対策
flatt_security
0
180
『三匹の子ぶた』から学ぶネットワークセキュリティの昔と今 / Network Security: Then and Now Through the Lens of The Three Little Pigs
nttcom
1
1.1k
CloudWatchから始めるAWS監視
butadora
0
310
「待ち時間」の消滅と「自我消耗」の加速:生成AI時代のエンジニアを救うメンタル・リソース管理
poropinai1966
0
400
20260724 情シスAI #1 「全従業員をAIネイティブにする」ために情シスがやっていること(公開版)
frtckty
0
180
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
8
2.1k
最高のシステムプロンプトを作るためにフィードバック機能を導入した話
alchemy1115
1
270
LLMリーダーボードアップデートに向けたAgentic Math_SWEのトレースについて
nejumi
0
190
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
330
The Limits of Empathy - UXLibs8
cassininazir
1
570
Become a Pro
speakerdeck
PRO
31
6k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
A Modern Web Designer's Workflow
chriscoyier
698
190k
A Soul's Torment
seathinner
6
3.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Optimizing for Happiness
mojombo
378
71k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
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 のパフォーマンスに物凄いポテンシャルを感じた