Sidekiq - 无法在5.000秒内获得数据库连接

Nic*_*nto 20 postgresql concurrency ruby-on-rails sidekiq

我在开发时在os x上使用Rails 4和Sidekiq得到以下警告

10:13:39 worker.1 | 2014-09-22T07:13:39.857Z 86981 TID-oug0oog10 WARN: could not obtain a database connection within 5.000 seconds (waited 5.002 seconds)
10:13:39 worker.1 | 2014-09-22T07:13:39.857Z 86981 TID-oug0oog10 WARN: /Users/me/.rvm/gems/ruby-2.1.3/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
Run Code Online (Sandbox Code Playgroud)

我读了其他答案,说减少我给sidekiq的并发性以允许更多其他东西,但是

worker: bundle exec sidekiq -c 10 
Run Code Online (Sandbox Code Playgroud)

它仍然无法正常工作

我正在使用Postgres.app

localhost中的数字/并发应该是什么?

小智 35

我将数据库池设置为sidekiq并发,现在它适用于我.

bundle exec sidekiq -c 10
Run Code Online (Sandbox Code Playgroud)

在我的database.yml中

development:
  adapter: postgresql
  ...
  host: localhost
  pool: 10
Run Code Online (Sandbox Code Playgroud)


小智 5

该问题与数据库池应该为“sidekiq_concurrency”+ 2这一事实有关。如果将其放入 sidekiq 初始值设定项中,您通常会解决该问题:

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
Run Code Online (Sandbox Code Playgroud)

  • “+ 2”与Redis连接有关,与数据库连接无关。现在甚至是“+ 5”,请参阅https://github.com/mperham/sidekiq/wiki/Using-Redis#complete-control (2认同)