Connection pool size in unicorn

Hi

I have had 100 unicorn workers per box for months and have had a pool size of 2. Never had a problem till today, i get these errors after deploying :

“could not obtain a database connection. The max pool size is currently 2; consider increasing it”

My understanding is that each unicorn worker gets its own pool. Since each worker keeps a persistent connection, 2 should be enough. Should i have a higher number than 2?

Thanks for getting in touch with us. Looking at your stack, having 100 Unicorn workers on a 16 GB server seems a bit excessive - is there any reason for having that many? With regards to the connection pool size, this depends entirely on your application:

“In Unicorn each process establishes its own connection pool, so if your db pool setting is 5 and you have 5 Unicorn workers then you can have up to 25 connections. However, since each unicorn worker can handle only one connection at a time, then unless your app uses threading internally each worker will only actually use one db connection.” http://stackoverflow.com/questions/22403952/is-my-understanding-of-unicorn-sidekiq-and-db-pool-size-correct

You can read more background about this here: https://devcenter.heroku.com/articles/concurrency-and-database-connections

I hope this helps. Please let me know if you have any further questions.

Thanks, this answers the question. I guess the error came because of some hanging unicorn workers.

You must be logged in to answer this question