redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Reduce default max_connections number

Open laukhin opened this issue 3 years ago • 6 comments

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:

  1. By default Redis instance can handle 10000 connections at a time which is far less than our default pool size.
  2. 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.
  3. 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 :)

laukhin avatar Jun 07 '22 13:06 laukhin

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

Fogapod avatar Dec 06 '22 10:12 Fogapod

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Jan 15 '24 00:01 github-actions[bot]

this is not solved..

Fogapod avatar Feb 15 '24 06:02 Fogapod

@Fogapod any workaround to this? do u just not set max_connections

anushkmittal avatar Mar 23 '24 04:03 anushkmittal

@Fogapod any workaround to this? do u just not set max_connections

I use blocking pool: https://github.com/redis/redis-py/issues/2517

Fogapod avatar Mar 23 '24 05:03 Fogapod

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.

mohd-akram avatar May 12 '24 21:05 mohd-akram