From a32565d72b4d3f54bb41f8f58ab481324f8eae1e Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma <32020192+tds-1@users.noreply.github.com> Date: Thu, 29 Jan 2026 20:53:41 +0530 Subject: [PATCH] fix: velma connection limit (#13395) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Make the $velma Redis connection pool size configurable via `REDIS_VELMA_SIZE` environment variable (default: 5, matching current behavior) The $velma pool is used exclusively by Rack::Attack for rate limiting and was the only Redis pool with a hardcoded size ## Fixes Under high traffic, the hardcoded $velma pool (size: 5) causes connection contention. Every HTTP request passes through Rack::Attack middleware, which requires a $velma Redis connection. When `WEB_CONCURRENCY=2` and `RAILS_MAX_THREADS=10` (20 concurrent threads), the 4:1 thread-to-connection ratio causes threads to queue for up to 1 second (the pool timeout), resulting in intermittent request latency spikes during traffic bursts. The $alfred pool was already configurable via REDIS_ALFRED_SIZE — this change brings $velma to parity. ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --- > [!NOTE] > **Low Risk** > Low risk: changes only Redis connection pool sizing for Rack::Attack; misconfiguration could cause rate-limiting Redis contention or extra connections but no data/auth logic changes. > > **Overview** > Makes the `velma` Redis connection pool (used by Rack::Attack) configurable via a new `REDIS_VELMA_SIZE` env var, replacing the previously hardcoded pool size. > > Documents `REDIS_VELMA_SIZE` in `.env.example` alongside the existing `REDIS_ALFRED_SIZE` setting. > > Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit dcbc946f2e1d7356dc743178ca46cdf12cb25c78. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot). --------- Co-authored-by: Vishnu Narayanan --- .env.example | 1 + config/initializers/01_redis.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 55750b2f2..bc7380a29 100644 --- a/.env.example +++ b/.env.example @@ -276,3 +276,4 @@ AZURE_APP_SECRET= # REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false # REDIS_ALFRED_SIZE=10 +# REDIS_VELMA_SIZE=10 diff --git a/config/initializers/01_redis.rb b/config/initializers/01_redis.rb index 84ae88d29..5d879d9e8 100644 --- a/config/initializers/01_redis.rb +++ b/config/initializers/01_redis.rb @@ -13,7 +13,8 @@ end # Velma : Determined protector # used in rack attack -$velma = ConnectionPool.new(size: 5, timeout: 1) do +velma_size = ENV.fetch('REDIS_VELMA_SIZE', 10) +$velma = ConnectionPool.new(size: velma_size, timeout: 1) do config = Rails.env.test? ? MockRedis.new : Redis.new(Redis::Config.app) Redis::Namespace.new('velma', redis: config, warning: true) end