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
スパイクアクセス対策としての pitchfork 導入
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Shia
December 06, 2024
Technology
1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
スパイクアクセス対策としての pitchfork 導入
RubyWorld Conference 2024 Day 2 の発表です。
https://2024.rubyworld-conf.org/ja/program/day2/#b-2-1
Shia
December 06, 2024
More Decks by Shia
See All by Shia
猫の手も借りたい
riseshia
0
36
Good Enough Types: Heuristic Type Inference for Ruby
riseshia
1
4.9k
Class.new is all you need
riseshia
1
730
型を書かないRuby開発への挑戦
riseshia
0
6.2k
ひとつの開発環境
riseshia
0
220
Conquering Massive Traffic Spikes in Ruby Applications with Pitchfork
riseshia
0
420
NewEngineering 2024 - 繋がっていくサービスを支える開発環境作り
riseshia
0
2k
Hotspot on Coverage
riseshia
0
320
差分ベースで効率的にテストを実行してみる
riseshia
1
850
Other Decks in Technology
See All in Technology
分析の民主化を支えるメタデータ整備の実践
kakehashi
PRO
4
1.3k
Jetson Orin Nanoとk3sとローカルLLMで音声文字起こしシステム作ってみた
y_sera15
0
120
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
150
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
4
1.2k
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
3
830
Classmethod Company Deck
satoshi7
0
170
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
110
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.3k
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
610
Getting Started with Google Antigravity
glaforge
0
250
アウトプット初心者、半年間のふりかえり
4o1sobblue
0
200
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
150
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Un-Boring Meetings
codingconduct
0
450
Exploring anti-patterns in Rails
aemeredith
4
530
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Building AI with AI
inesmontani
PRO
1
1.3k
A Soul's Torment
seathinner
8
3.7k
The untapped power of vector embeddings
frankvandijk
2
1.9k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
550
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
520
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Transcript
スパイクアクセス対策としての pitchfork 導入 Ruby World Conference 2024 Sim Sangyong@STORES
Self introduction - Sangyong Sim @ STORES. Inc - shia
@ Internet - riseshia @ {X, GitHub} 2
STORES ネットショップ 3
- 多様な規模の事業者 - 特定時刻から販売を開始することができる - 規模を正しく予測するのは難しい STORES ネットショップ 4
xx/xx 10時から数量限定グッズ販売開始します!!! 5 more than 10x
レイテンシが劣化する 6 p95 p90 p50
(できれば何もせずに) スパイクアクセス時にも安定した購入体験ができる ようにしたい!!! 目標 7
- リクエストをできるだけ待たせない ~= 十分な数のWebサーバのワー カーを用意する - p90 あたりから観測されるレイテンシ劣化を改善する 注: このセッションではアプリケーション高速化およびキャッシングによ
る負荷軽減はスコープ外なので話しません 課題 8
環境 9 - ECS Fargate 上で動く - ASG(Auto Scaling Group)
でキャパシティ管理する - Ruby on Rails / unicorn で動く
- 正確にトラフィックを予測することはできないので過去の実績ベース で戦略を考える - 予想を超えてしまった場合はしょうがないので待ちを許す(しかない) - ほとんどのスパイクのピークは 1分以下で 5分以内でほぼ捌き終わるの で、
ASG では間に合わないため 課題 - 十分な数のWebサーバのワーカーを用意する 10
小規模のもの - 常に過剰キャパシティを持ってスパイクが発生したらそれで吸収する - ECS Fargate Spot で格安で運用できている 大規模なもの -
まれに来るそれ以上のスパイク、規模感から事前に把握してることが 多く、販売直前でサービスをスケールアウトする 課題 - 十分な数のWebサーバのワーカーを用意する 11
リクエスト平均処理時間を 内部の処理時間で分類 課題 - レイテンシ劣化を改善する 12 Ruby p95 p90 p50
DB 外部通信
課題 - レイテンシ劣化を改善する 13 もしかして Webサーバのワーカー、温まってない...?
Webサーバのワーカー、温まってないとは 14 Webサーバ(Rails アプリケーション)は起動して実際リクエストが処理する ことで初めて走る処理が色々あり、それらによって起動直後は遅いことがある - 各種の TCP コネクション生成 -
インメモリーキャッシュ生成 - (YJIT を有効にしている場合) JIT コンパイル - method_missing から始まるメタプロ - Action View のコンパイル - …
なぜ一部だけ? - 実験 15 unicorn でリクエストを処理する時、どのワーカーが仕事していたのかの 確認をしてみる - 処理に 0.1s
かかるエンドポイント - ワーカー数 8 - 低負荷の再現するため 2並列 - 10s 負荷 各ワーカーが処理したリクエストの数を調べてみる
なぜ一部だけ? - 実験 16 - worker 0: 85 - worker
1: 86 - worker 2: 2 - worker 3: 0 - worker 4: 0 - worker 5: 0 - worker 6: 0 - worker 7: 0 注:Linux 環境のみ再現します
- unicorn は prefork 型 web サーバ - 起動して要求された数のワーカーを fork
し新しいプロセスを生成 - 1つの TCP ソケットが共有される - unicorn では epoll(or kqueue) というのが使われる - この通知順番はどうなっているか なぜ偏る? 17 ソケット epoll ワーカー0 ワーカー1 ワーカーn … 監視 通知
なぜ偏る? 18 - リクエストが来た時、それを処理するワーカーが順番に並んてる キューを想像すると、そのキューは LIFO - 処理が終わったワーカーがキューに入ったら、次のリクエスト時にも同じ ワーカーが選ばれるので偏る Ref:
https://blog.cloudflare.com/the-sad-state-of-linux-socket-balancing/ epoll ワーカー1 ワーカー2 … 通知 待ち列 ワーカー0 処理が終わったら待ち列の先頭に入る
- スパイクに備えて過剰キャパシティを確保する - 過剰に確保されたワーカーは起動してから仕事していない - 販売開始時刻の大量のリクエストにより遊んでいたワーカーが仕事を 始める - 温まってないので処理に時間がかかる...? つまり起きてるのはおそらく
19
どうやって全ワーカーを温める? - 実際トラフィックを作って温める - 温まった状態でサービスインする - puma にする - ??
20
- Shopify による unicorn の fork - refork という機能がある pitchfork
21
COMMAND \_ pitchfork master \_ (gen:0) mold \_ (gen:0) worker[0]
\_ (gen:0) worker[1] \_ (gen:0) worker[2] \_ (gen:0) worker[3] COMMAND \_ pitchfork master \_ (gen:1) mold \_ (gen:1) worker[0] \_ (gen:1) worker[1] \_ (gen:1) worker[2] \_ (gen:1) worker[3] pitchfork - refork - 一定数(adjustable)のリクエストを処理したワーカーをテンプレート として全ワーカーを再度 forkする - Copy on Write(CoW) による共有メモリーを増やしてメモリー使用量 を減らす戦略 22 fork promote
温まったワーカーを refork すると 全ワーカーが温まった状態になるのでは? pitchfork 23
導入 - pitchfork が問題ないか確認するために開発環境でしばらく運用 - 本番を徐々にロールアウト 24
fork safety 確認が必要 - コネクションが継承されるとか - バックグラウンドで動くスレッドの扱いとか 相性が悪い事例もあるので気をつける Ref: https://github.com/Shopify/pitchfork/blob/master/docs/FORK_SAFETY.md
導入の注意点 25
毎年定期的に開催されている大きい販売の比較。 グラフの高さは同じスケールに調整されてます。 導入結果 26 rps(2023) rps(2024)
導入結果 27 レイテンシ(2024) レイテンシ(2023) p95 p90 p50 p95 p90 p50
導入結果 28 レイテンシ(2024) レイテンシ(2023) Ruby DB 外部通信 Ruby DB 外部通信
p95 p90 p50 p95 p90 p50 リクエスト平均処理時間を 内部の処理時間で分類(2023) リクエスト平均処理時間を 内部の処理時間で分類(2024)
不規則なスパイクアクセスの処理のため、低コストの効率的な暖気手段と して pitchfork を試して一定の成果がありました まとめ 29
ご清聴ありがとうございました まとめ 30