Sidekiq - could not obtain a database connection within 5.000 seconds

前端 未结 3 961
遇见更好的自我
遇见更好的自我 2020-12-16 12:10

I get the following warning with Rails 4 and Sidekiq on os x on development

10:13:39 worker.1 | 2014-09-22T07:13:39.857Z 86981 TID-oug0oog10 WARN: could not          


        
相关标签:
3条回答
  • 2020-12-16 12:42

    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

    0 讨论(0)
  • 2020-12-16 12:52

    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
    
    0 讨论(0)
  • 2020-12-16 12:54

    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
    
    0 讨论(0)
提交回复
热议问题