On Friday, June 20, 2014 5:42:40 AM UTC-7, Oldřich Vetešník wrote: > > Hello Jeremy, > > We tried to play around with concurrency and (database) connection limit > and were not sure how to correctly set (database) connection pool. > Do you think these calculations are correct? > > - Platform: Heroku > - Dynos: 2 > - Webserver: Puma > - Puma workers (processes): 4 > - Max threads per worker: 10 > > Therefore: > > - Max number of connections: 2 dynos * 4 workers * 10 threads = 80 > connections > - Number of pools: 2 dynos * 4 workers = 8 pools in total > - Connection pool size: 10 threads = 10 connections > - Which multiplies back to 80 > > The idea of the pool is that connections in the pool are shared between threads. However, the default max connections per pool in Sequel is 4. So it's is 2 dynos * 4 workers * 4 connections per pool = 32 connections
Now, you can change the maximum connections per pool to 10 if you want via the :max_connections option. But unless all of your threads are going to be using the database 100% of the time, you generally need fewer connections per pool than you have threads. If you want to share PostgreSQL database connections between dynos/worker processes, you need to use something like pgbouncer. Looks like there is a heroku buildpack for that: https://github.com/gregburek/heroku-buildpack-pgbouncer Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
