【问题标题】:Sidekiq stopped processing jobs in queueSidekiq 停止处理队列中的作业
【发布时间】:2018-09-27 16:07:34
【问题描述】:

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"?

我正在通过 Heroku 运行 PG Hobby。它的连接限制是 20。这是问题的根源吗?

【问题讨论】:

  • 关于“是否可以让 Sidekiq 强制运行作业?”,是的,可以检查队列以及 Sidekiq 监视器上正在处理的内容:github.com/mperham/sidekiq/wiki/Monitoring
  • @AndreDurao 监控仅提供删除排队作业的选项。例如,在邮件中,我想强制运行该作业。
  • 您是否尝试重新启动工作器? devcenter.heroku.com/articles/…
  • @AndreDurao 是的。作业仍在排队中。
  • @AndreDurao 看到上面的更新。结果发现工人经常崩溃。

标签: ruby-on-rails ruby sidekiq


【解决方案1】:

经过 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 会解决剩下的问题。

【讨论】:

  • 您也可以将pool: 30 添加到database.yml 并删除那部分hacky 配置。
  • 太美了!谢谢@MikePerham
猜你喜欢
  • 2015-07-06
  • 1970-01-01
  • 2013-06-16
  • 1970-01-01
  • 2013-05-26
  • 1970-01-01
  • 2015-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多