Skip to content

Instantly share code, notes, and snippets.

@tai2
Last active March 23, 2022 06:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tai2/04202c605774745d3d42cef0d5d595a8 to your computer and use it in GitHub Desktop.
Save tai2/04202c605774745d3d42cef0d5d595a8 to your computer and use it in GitHub Desktop.
Rails/Sidekiqアプリにおけるconcurrency, connection poolまわりの設定条件

Rails/Sidekiqアプリにおけるconcurrency, connection poolまわりの設定条件

rails redis concurrency

https://whimsical.co/SJK9Qzo733f6jkw1Tfk4dT

仮定

  • サーバーインスタンス(dyno)、ワーカーインスタンス(dyno)はそれぞれ1つずつ
  • Sidekiqジョブは毎回DB接続を要求する

満たすべき条件

  • puma threads <= db pool size
  • puma threads <= sidekiq client connection pool size
  • sidekiq concurrency <= db pool size
  • sidekiq concurrency + 5 <= sizekiq server connection pool size
  • puma workers * sizekiq client connection pool size + sidkiq server connection pool size <= redis max clients
  • puma workers * (db pool size + 1) <= rdb max connections

その他

  • 上記は、puma threads * puma workersの同時リクエスト数を捌くための必要条件
  • 実際には、Bad connectionsなどがあるので、ある程度余裕を持たせる必要がある
  • モニタリングシステムやCLIなどもコネクションを消費するので、それらも考慮する必要がある

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment