change the 'max number of client reached' redis error message to ''

3.3k views Asked by At

is it possible to change the error message 'max number of client reached' to null or empty string?

I'm using redis as a cache for my DB values and in cases that I can't get the values from the cache I will get it from the DB. if I could configure it in the redis it self it would be the best option for me because my code won't have to change in order to support that edge case.

if someone has some tips on how to avoid such errors it would be nice as well :) (I'm using php scripts with predis package)

1

There are 1 answers

7
Tom Lime On BEST ANSWER

The error message max number of clients reached is clearly indicate that Redis is reached client limit and unable to serve any new requests.

  • this issue probably can be related to incorrect use of Predis\Client in code. Instead to create a connection object once (singleton) and use it across process lifetime. The code probably create a new object on every request to Redis and keep all these connections open.
  • another thing is worth to check how php processes are managed by a web server. The web server (e.g. apache prefork, nginx php-fpm) might leave processes for a long time both holding connections to Redis and exhaust server resources (mem, cpu).
  • if nothing from above is true - the issue (bug) might be in the predis library.

Bottom line: the code/web server exhaust maxclients limit.

If you don't have control over code/web server (e.g. nginx), to reduce amount of error messages you can:

  • increase maxclients over 10k (depends on your Redis server resources). This will reduce frequency of error messages.
  • consider to enable (disabled by default) connection timeout (use it with cautious, as your code may assume that connections are never timeout). This will release old connections from a connection pool.
  • decrease tcp-keepalive from 300 seconds to less than timeout. This will close connections to dead peers (clients that cannot be reached even if they look connected).