I have Unicorn, Sidekiq and Postgres setup.
I am trying to understand the right configuration to set up so that I don't hit the maximum db connection limit. In Opsworks, the m1.small Postgres RDS instance can have a max of 121 connections.
I have a db pool size of 5.
Consider this. Sidekiq and Unicorn are its own process. So the db pool size for each process is 5. Correct me if my understanding here is wrong.
If I have 5 unicorn process', that means 5*5=25 database connections
Now this is the part where I am slightly confused, since Sidekiq is multithreaded. If Sidekiq has a concurrency of 5. and the db pool size is also set to 5. Does that mean 25 potential db connections at a given time too?
This means, for one instance, I could have 50 db connections?
A connection pool maintains a specific number of open database connections to an application in the main memory. The default size of the database connection pool is eight, but you can change this number while deploying or updating an application in the SAP BTP cockpit.
To set the maximum pool size: n is the number of connections allowed per pool, from 1 to 2,147,483,647 (the default). The number of connections is limited by the number of connections supported by your database driver.
What is database connection pooling? Database connection pooling is a way to reduce the cost of opening and closing connections by maintaining a “pool” of open connections that can be passed from database operation to database operation as needed.
pool is the config of size of connection pool, which is 5 by default.
In Unicorn each process establishes its own connection pool, so you 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.
In Sidekiq, the connections in the pool are shared across threads, so you need to have at least one connection available per worker. If you have a concurrency of 5, then your pool needs to be at least 5.
Having a pool size greater than 1 means each Unicorn worker has access to connections it can't use, but it won't actually open the connections, so that doesn't matter.
The total number of actual connections your app requires, unless you're using threads in your application code (and they don't share a db connection), is one per Sidekiq worker plus one per Unicorn worker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With