【问题标题】:Sidekiq ignoring concurrency when using multiple queuesSidekiq 在使用多个队列时忽略并发性
【发布时间】:2020-11-03 13:43:47
【问题描述】:

我有两个队列:developmentar_updater。我有一堆 sidekiq 工作人员不断更新 ActiveRecord 对象,但有时他们同时查询记录,而不是仅在另一个人更新它之后。因此,我正在考虑只创建一个队列并将其并发限制为 1,以便可以附加正确的数据。

这是我的config/sidekiq.yml 文件:

development:  
  :concurrency: 10
ar_updater:
  :concurrency: 1
:queues:
  - development
  - ar_updater

然后我只有一个简单的工人,看起来像这样:

class ArUpdateWorker
  include Sidekiq::Worker
  sidekiq_options queue: "ar_updater"

  def perform(options)
    options = options.transform_keys(&:to_sym)
    schedule_id = options[:schedule_id]
    progress = options[:progress]

    schedule = Schedule.find(schedule_id)
    old_progress = schedule.current_progress
    schedule.update(current_progress: old_progress + progress)
  end
end

有没有办法确保这些工作人员在这个特定队列中一次只运行一个?当多次调用ArUpdateWorker 时,sidekiq 似乎忽略了并发性,只是根据需要运行 worker,但是如果我将 worker 的队列切换到 development,那么它会遵守 10 的并发性。有点混乱。

似乎解决此问题的唯一方法是使用在命令行界面上设置的并发设置运行 sidekiq

【问题讨论】:

    标签: ruby-on-rails sidekiq


    【解决方案1】:

    你实际上不能这样做。您有一个名为development 的队列。这可能会非常令人困惑,因为您还会有一个名为 development 的环境。

    您的配置将名为“开发”的环境的配置设置为 10,而不是队列。根据环境,sidekiq 进程将具有一个并发设置。您不能将该进程设置为具有不同的并发级别。

    这是一个类似的问题: How can I specify different concurrency queues for sidekiq configuration?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 2020-04-21
      相关资源
      最近更新 更多