Skip to content

Instantly share code, notes, and snippets.

@c2k
Created June 11, 2014 21:14
Show Gist options
  • Save c2k/d561df8c60d16127af42 to your computer and use it in GitHub Desktop.
Save c2k/d561df8c60d16127af42 to your computer and use it in GitHub Desktop.
Puma on Heroku

Notes from https://discussion.heroku.com/t/using-puma-on-heroku/150/11?u=ckobayashi

(Number of Puma workers per dyno * * max number of threads per worker * number of dynos) + headroom = number of required connections.

So in your case: 7 * 16(?) * 4(?) = 448 db connections

The max of 16 threads per worker is Puma's default and can be overridden to something more inline with your needs. In reality, you probably won't need all 448 connections since it's unlikely, but not impossible, that all threads will grab a connection from the pool at the same time.

To see what your actual connection usage is like, I would suggest taking a look at the Postgres metrics in your log stream to see how many connections are open at any one time (this is only available on production tier dbs):

$ heroku logs | grep "sample#active-connections"
    2013-10-24T15:26:29+00:00 app[heroku-postgres]: source=HEROKU_POSTGRESQL_BRONZE ... sample#active-connections=28 ...

The sample#active-connections token contains the number of db connections in use by your app (and all other processes/one-off dynos).

You can also manually query your db for this info:

    > select count(*) from pg_stat_activity where pid <> pg_backend_pid()  and usename = current_user;

     count
    -------
       28
    (1 row)

Edit: Updated to include thread count as factor for determining number of db connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment