Enable static & dynamic configuration of Redis connection pool size
What does this MR do?
We currently use hard coded values for configuring redis connection pools at runtime.
Rather than relying on hard-coded constants, we now first try to read a user specified value for the connection pool size from resque.yml. If that does not exist, we fall back to set a sensible default based on the current environment's concurrency settings.
To that end, two changes were made:
- In
resque.yml
, where the remaining redis config resides, a new option can be specified (connection_pool_size
), forpuma
,unicorn
andsidekiq
. Whenever this config is present, it takes effect as-is. - If no user specified values are supplied, we default to a pool size of
concurrency + 50%
(concurrency meaning the number of worker threads per process). The added 50% are to account for other non-worker threads trying to connect to Redis (this is just a theoretical maximum; connections in the pool are created lazily so this cap comes essentially free). I chose a factor instead of adding a constant so that the pool size scales with the concurrency level of the runtime. It's just a heuristic though; as long as we don't see clients timing out while waiting for connections to become available, we're good.
TODO:
-
Split up pool size config into web specific and job specific work loads -
Apply a factor for extra head room -
do not pass along non-Redis client cfg from what we parse from resque.yml
Does this MR meet the acceptance criteria?
Conformity
Availability and Testing
Upon deploying this, the behavior compared to now would change as follows:
- Unicorn worker Redis pool size will shrink from 5 to
round(1.5 * 1)
(= 2) - Sidekiq worker Redis pool size will change from
5 + num_threads
toround(1.5 * num_threads)
- Puma worker Redis pool size will change from 5 to
1.5 * num_threads
This is assuming that we do not provide a default for connection_pool_size
in resque.yml
. Otherwise all cases collapse to using the specified connection_pool_size
for the given runtime.
Closes #35559 (closed)
Edited by 🤖 GitLab Bot 🤖