title: Puma Cluster configuration on Heroku
body: <p>I need some help with my configuration of Puma (Multi-Thread+Multi-Core Server) on my RoR4 Heroku app.
  The Heroku docs on that are not quite up-to-date. I followed this one: <a href="https://devcenter.heroku.com/articles/concurrency-and-database-connections">Concurrency and Database Connections</a> for the configuration, which does not mention the configuration for a Cluster, so I had to use both types together (threaded and multicore).</p>
  
  <p><strong>My current configuration:</strong></p>
  
  <p><em>./Procfile</em></p>
  
  <pre><code>web: bundle exec puma -p $PORT -C config/puma.rb
  </code></pre>
  
  <p><em>./config/puma.rb</em></p>
  
  <pre><code>environment production
  threads 0,16
  
  workers 4
  preload_app!
  
  on_worker_boot do
    ActiveRecord::Base.connection_pool.disconnect!
  
    ActiveSupport.on_load(:active_record) do
      config = Rails.application.config.database_configuration[Rails.env]
      config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
      config['pool']              = ENV['DB_POOL'] || 5
      ActiveRecord::Base.establish_connection
    end
  end
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <p>a) Do I need the before_fork / after_fork configuration like in Unicorn, since the Cluster workers are forked?.<br>
  b) How do I tune my thread count depending on my application - what would be the reason to drop it down? / In what cases would it make a difference? Isn't 0:16 already optimized?<br> 
  c) The Heroku database allows 500 connections. What would be a good value for DB_POOL depending on thread, worker and dyno count? - Does every thread per worker per dyno require a sole DB connection when working parallely?</p>
  
  <p>In general: How should my configuration look like for concurrency and performance?</p>