Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I have Ruby on Rails application deployed to Heroku where ActiveRecord-calls seem to take long. The application itself requires that the DB is polled pretty frequently, though there are some querys, indexing and parts of code that could be improved to speed things up. Currently there are 4 dynos with standard-tier DB. My Unicorn.rb looks like this

worker_processes 3
timeout 30
preload_app true

before_fork do |server, worker|
  @sidekiq_pid ||= spawn("bundle exec sidekiq -c 2")
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end


  if defined?(ActiveRecord::Base)
    config = ActiveRecord::Base.configurations[Rails.env] ||
        Rails.application.config.database_configuration[Rails.env]
    config['pool'] = ENV['DB_POOL_SIZE'] || 5        ActiveRecord::Base.establish_connection(config)
  end
end

DB_POOL_SIZE is currently set as 10. Is this too many? If I understood correctly how https://devcenter.heroku.com/articles/concurrency-and-database-connections works, should it be around 3, plus a few extra for bad connections? Also if I increase the size of web dynos, I don't need to scale up DB_POOL_SIZE, right?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.