Sidekiq 停止处理队列中的作业
Sidekiq stopped processing jobs in queue
Sidekiq 一直在处理作业(一夜之间完成了 30 个作业)。今天早上,它完全关闭了处理队列(现在最多 28 个作业)。
运行 在 Heroku 上(1 个 Standard-2x Web Dyno,1 个 Standard-1x Worker Dyno)。
Procfile(我最难找到要配置的文档)
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
sidekiq.yml
development:
:concurrency: 5
production:
:concurrency: 20
:queues:
- ["default", 1]
- ["mailers", 2]
sidekiq.rb
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'], size: 2 }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'], size: 20 }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
# config['pool'] = ENV['WORKER_DB_POOL_SIZE'] || Sidekiq.options[:concurrency]
config['pool'] = 16
ActiveRecord::Base.establish_connection(config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end
end
end
end
此外,队列中的所有作业(默认,邮件程序)是否可以让 Sidekiq 强制 运行 作业?
更新
我已将错误缩小到 Heroku 工作人员。重启后,worker 很快就崩溃了。
第一个错误与 Sidekiq 没有生成足够的连接有关(Redis 需要 22 个,我已将限制设置为 20 个)。
现在,我收到以下错误:
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我是 运行宁 PG Hobby 通过 Heroku。它的连接限制是 20。这是问题的根源吗?
经过 2 天的冒险,感谢 this SO question 找到了答案。希望这有助于未来围观者的 SEO。
我将 sidekiq.rb 文件更改为
sidekiq.rb
require 'sidekiq/web'
Sidekiq.configure_server do |config|
ActiveRecord::Base.configurations[Rails.env.to_s]['pool'] = 30
end
if Rails.env.production?
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
end
然后,我将 sidekiq.yml 更新为
sidekiq.yml
queues:
- default
- mailers
:verbose: false
:concurrency: 5 # Important to set depending on your Redis provider
:timeout: 8 # Set timeout to 8 on Heroku, longer if you manage your own systems.
注意: 也可以选择忽略初始化文件中 if 语句中的所有内容。正如 Sidekiq 的创建者所说,您可以将 heroku 配置设置为:
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
Sidekiq 会解决剩下的问题。
Sidekiq 一直在处理作业(一夜之间完成了 30 个作业)。今天早上,它完全关闭了处理队列(现在最多 28 个作业)。
运行 在 Heroku 上(1 个 Standard-2x Web Dyno,1 个 Standard-1x Worker Dyno)。
Procfile(我最难找到要配置的文档)
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
sidekiq.yml
development:
:concurrency: 5
production:
:concurrency: 20
:queues:
- ["default", 1]
- ["mailers", 2]
sidekiq.rb
if Rails.env.production?
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'], size: 2 }
end
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'], size: 20 }
Rails.application.config.after_initialize do
Rails.logger.info("DB Connection Pool size for Sidekiq Server before disconnect is: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
ActiveRecord::Base.connection_pool.disconnect!
ActiveSupport.on_load(:active_record) do
config = Rails.application.config.database_configuration[Rails.env]
config['reaping_frequency'] = ENV['DATABASE_REAP_FREQ'] || 10 # seconds
# config['pool'] = ENV['WORKER_DB_POOL_SIZE'] || Sidekiq.options[:concurrency]
config['pool'] = 16
ActiveRecord::Base.establish_connection(config)
Rails.logger.info("DB Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
end
end
end
end
此外,队列中的所有作业(默认,邮件程序)是否可以让 Sidekiq 强制 运行 作业?
更新
我已将错误缩小到 Heroku 工作人员。重启后,worker 很快就崩溃了。
第一个错误与 Sidekiq 没有生成足够的连接有关(Redis 需要 22 个,我已将限制设置为 20 个)。
现在,我收到以下错误:
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我是 运行宁 PG Hobby 通过 Heroku。它的连接限制是 20。这是问题的根源吗?
经过 2 天的冒险,感谢 this SO question 找到了答案。希望这有助于未来围观者的 SEO。
我将 sidekiq.rb 文件更改为
sidekiq.rb
require 'sidekiq/web'
Sidekiq.configure_server do |config|
ActiveRecord::Base.configurations[Rails.env.to_s]['pool'] = 30
end
if Rails.env.production?
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV["REDISTOGO_URL"]}
end
end
然后,我将 sidekiq.yml 更新为
sidekiq.yml
queues:
- default
- mailers
:verbose: false
:concurrency: 5 # Important to set depending on your Redis provider
:timeout: 8 # Set timeout to 8 on Heroku, longer if you manage your own systems.
注意: 也可以选择忽略初始化文件中 if 语句中的所有内容。正如 Sidekiq 的创建者所说,您可以将 heroku 配置设置为:
heroku config:set REDIS_PROVIDER=REDISTOGO_URL
Sidekiq 会解决剩下的问题。