vapor / redis

Vapor provider for RediStack
MIT License
458 stars 57 forks source link

ERR max number of clients reached on Heroku free tier #167

Closed jstorm31 closed 3 years ago

jstorm31 commented 4 years ago

I'm hosting my server on Heroku free Dyno and I've been getting (Redis) ERR max number of clients reached recenty.

I've found out it could be solved either by setting a shorter timeout on Heroku or connection pooling. There was a method for pooling in Vapor 3 req.withPooledConnection(to: .redis), but I haven't found such a method in Vapor 4, so I use directly req.redis.anyCommand(...).

My questions:

  1. Is this just a free dyno problem or a problem in my application?
  2. Is there a pooling of connections for Redis in Vapor 4?

EDIT: When I checked the Redis Heroku dashboard, there were 16 - 20 clients connected and never disconnected. I wonder how is that possible. 🤔 Nevertheless, I could kill all connections from Redis site with Heroku cli heroku redis:cli and running CLIENT KILL TYPE normal. I think that won't fix the problem though.

Mordil commented 3 years ago

@jstorm31 Pooling is done under the hood in Vapor 4.

Each EventLoop is given an RedisConnectionPool, so if your configuration says to populate a pool with 4 connections, and you have 4 EventLoops, then you will have 16 total connections.

Try modifying the configuration with app.redis.configuration.pool.

In the next week or so, documentation will improve as Vapor/Redis moves to full 4.0 release

jstorm31 commented 3 years ago

I see, thank you 🙂