Sidekiq - could not obtain a database connection within 5.000 seconds

强颜欢笑 提交于 2019-11-30 11:03:13

I set database pool to sidekiq concurrency and now it works for me.

bundle exec sidekiq -c 10

in my database.yml

development:
  adapter: postgresql
  ...
  host: localhost
  pool: 10
Jacopo Beschi

The probem is related to the fact that database pool should be 'sidekiq_concurrency' + 2. If you put this into your sidekiq initializer you will solve the problem in general:

Sidekiq.configure_server do |config|
     config = ActiveRecord::Base.configurations[Rails.env] ||
         Rails.application.config.database_configuration[Rails.env]
     config['pool'] = Sidekiq.options[:concurrency] + 2
     ActiveRecord::Base.establish_connection(config)
     Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end

Database connection size should be one plus the concurrency if we are using rails < 5.2 . Here is the corresponding GitHub issue. https://github.com/mperham/sidekiq/issues/4252

If there are 5 threads then the db pool size should be 6 in rails < 5.2 version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!