Repository navigation
Allow capping the redis connection pool - #7307
Conversation
|
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Move the pool cap checks into _redis_pool_limits so get_redis stays flat. A zero pool timeout made a saturated pool fail at once, which is the behavior the blocking pool replaces. Clarify in the news fragments that the cap applies to each Redis client.
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
You’re at about 91% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
Refs #7179
get_redis() uses a bare Redis.from_url, so the pool can grow to whatever peak concurrency a worker ever sees and then keeps those sockets open. Setting max_connections in the URL does cap it, but from_url builds a plain ConnectionPool, which raises MaxConnectionsError at the cap instead of waiting.
This adds an opt-in cap. When REFLEX_REDIS_MAX_CONNECTIONS is set, get_redis() builds a BlockingConnectionPool of that size, so callers wait for a free connection (up to REFLEX_REDIS_POOL_TIMEOUT, default 2s) instead of failing. Nothing changes unless you set it.
A few notes:
Tested with the repro from the issue against fakeredis with some added latency: unset grows to 101 connections, ?max_connections=10 drops 91 of 100 ops, REFLEX_REDIS_MAX_CONNECTIONS=10 holds at 10 with no failures. Unit tests, ruff and a scoped pyright run pass locally. Full pyright ran out of memory on my machine, and I didn't run the redis-backed tests against a real server.
AI help: used for parts of this change.