ruby-on-rails-3herokuruby-on-rails-3.2

How to find current connection pool size on heroku


We have a rails 3.2(.11) app with many dynos running on the heroku bamboo stack, connecting to a MySQL RDS server. There seem to be some issues with our current database connections, so we are trying to debug exactly how many connections each dyno is spinning up. I know I can set the size of a connection pool in the DATABASE_URL config on heroku, but can't seem to find out how many connections are currently being used by default.

Two main questions:

1) How can I find the size of the connection pool used by heroku?

2) Is there any reason why a dyno would need a connection pool size greater than 1? My understanding is that rails can only execute 1 request at a time so one database connection should be all that is needed as far as I can see.


Solution

  • To check the pool size, start a heroku console heroku run rails c, and run:

    ActiveRecord::Base.connection_pool.size
    

    Some webservers such as Puma are multithreaded, so the DB pool size matters. You can also run a multi-threaded worker such as Sidekiq, which also will be affected by the pool size.

    Note that Heroku will ignore your database.yml file. To set the pool size you can append ?pool=25 to the DATABASE_URL in your heroku app's configuation.