You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查询Sidekiq指定队列的当前运行线程数

Checking Running Thread Count for a Specific Sidekiq Queue (with sidekiq-limit_fetch)

Since you're using sidekiq-limit_fetch to enforce queue limits, there are a few straightforward ways to verify your configuration and get the current running thread count for a target queue:

1. Use sidekiq-limit_fetch's Built-in API

The gem maintains internal state for queue limits and running counts, so you can directly access this data:

# Replace with your target queue name
target_queue = "my_critical_queue"

# Fetch current running threads for the queue
current_running = Sidekiq::LimitFetch::Queues.running[target_queue] || 0

puts "Queue #{target_queue} has #{current_running} active threads (limit: #{Sidekiq::LimitFetch::Queues.limits[target_queue]})"

This gives you both the current running count and the configured limit in one go, making it easy to confirm if your limits are being respected.

2. Filter Sidekiq::Workers by Queue

If you prefer using Sidekiq's core API, you can iterate through active workers and count those assigned to your target queue:

target_queue = "my_critical_queue"

running_count = Sidekiq::Workers.new.count do |_process_id, _thread_id, work_details|
  work_details["queue"] == target_queue
end

puts "Queue #{target_queue} has #{running_count} active threads"

Each entry from Sidekiq::Workers.new includes a work_details hash with the queue key, so we filter and count matching entries to get the running thread count.

3. Check the Sidekiq Web UI

If you have the Sidekiq Web UI enabled, sidekiq-limit_fetch adds queue-specific limit and running count information directly to the Queues page. This is a quick, no-code way to verify your limits are active at a glance.

All these methods work in a Rails console, Sidekiq script, or even a custom monitoring endpoint you build for your application.

内容的提问来源于stack exchange,提问作者David Geismar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:27:27