redis-py
redis-py copied to clipboard
Reduce default max_connections number
Version: 4.3.3
Platform: Python 3.10 (actually any python)
Description: By default, there is a 2**31 max connection pool size. Such a large number seems unreasonable and unsafe to me for several reasons:
- By default Redis instance can handle 10000 connections at a time which is far less than our default pool size.
- Such an enormous pool size could lead to a DDoS attack on the Redis instance if used without proper care. Actually, it happened with our production not so long ago - we had some problems with a load and it led to our connections pool growing infinitely. Our Redis instances just couldn't recover from a massive amount of new connections. With a stricter connections size policy we could avoid that.
- I made some research and other Redis clients have a much stricter pool policy. For example, the Java client has 8 connections by default. Unofficial go client implementation has 10 connections per CPU by default.
My suggestion is to reduce the default max_connections number (both in sync and async versions) to provide a safe configuration by default and let the end-user override it to fine-tune the performance for its needs. The number is discussable, I'd stay for about 100 default connections. I can handle this issue if you will decide to fix that :)
I started getting ConnectionError: Too many connections after setting max_connections=50 on 4.4.0. Looks like connections aren't released properly and 2**31 hides that fact?
relevant line: https://github.com/redis/redis-py/blob/c54dfa49dda6a7b3389dc230726293af3ffc68a3/redis/asyncio/connection.py#L1532
Why would pool ever raise Too many connections, it should just wait instead
This issue is marked stale. It will be closed in 30 days if it is not updated.
this is not solved..
@Fogapod any workaround to this? do u just not set max_connections
@Fogapod any workaround to this? do u just not set max_connections
I use blocking pool: https://github.com/redis/redis-py/issues/2517
Running into this as well. Seems it's all to easy to DoS a server with the current defaults. Looks like #3200 aims to solve this.