在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工作人员。重新启动后,工作人员很快崩溃。
第一个错误与Sidekiq没有产生足够的连接(Redis需要22,我已经将限制设置为20)。
现在,我收到以下错误:
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
我通过Heroku运行PG Hobby。它的连接限制是20.这是问题的根源吗?
答案 0 :(得分:0)
经过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会弄明白其余的。