Skip to content

Fixes bug where queue weights are not honored anymore - #166

Open
StevenJL wants to merge 1 commit into
d34ndev:masterfrom
StevenJL:master
Open

Fixes bug where queue weights are not honored anymore#166
StevenJL wants to merge 1 commit into
d34ndev:masterfrom
StevenJL:master

Conversation

@StevenJL

@StevenJL StevenJL commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #165

Since 4.4.1, Queues#start calls .uniq on the queue list at boot. Sidekiq encodes a queue weight of N by repeating the queue name N times (Sidekiq::CLI#parse_queue on 6.x, Capsule#queues= on 7.x), and weighted_order!'s @queues.shuffle.uniq derives the weighted fetch order from those duplicates — so deduping at boot collapses weighted mode into a uniform shuffle. Measured with a 20:1 weighted pair: the heavy queue is polled first ~95% of cycles on 4.4.0 and ~50% on 4.4.1, on both sidekiq 6.5.12 and 7.3.9 (repro script in the issue).

This PR makes start take the already-expanded list from where each Sidekiq version keeps it, without deduping:

  • Sidekiq 6.x: config[:queues] (expanded by the CLI) — as 4.3.2/4.4.0 did.
  • Sidekiq 7.x: capsule.queuescapsule.config[:queues] holds the raw [[name, weight], …] YAML shape (Config#merge! is a plain hash delegate), so the previous map { queue.first } dropped the weights there too. Strictness now comes from capsule.mode == :strict, since the Sidekiq 7 CLI never sets config[:strict] — this also fixes strict (unweighted) configs wrongly getting weighted_order! on 7.

The per-fetch dedup that BRPOP needs already happens downstream (shuffle.uniq in weighted_order!, @queues.uniq! in strict_order!), where it is lossless because the weight information has already been converted into list position.

Since 4.4.1, `Queues#start` calls `.uniq` on the queue list at boot. Sidekiq encodes a
queue weight of N by repeating the queue name N times (`Sidekiq::CLI#parse_queue` on
6.x, `Capsule#queues=` on 7.x), and `weighted_order!`'s `@queues.shuffle.uniq` derives
the weighted fetch order from those duplicates — so deduping at boot collapses weighted
mode into a uniform shuffle. Measured with a 20:1 weighted pair: the heavy queue is
polled first ~95% of cycles on 4.4.0 and ~50% on 4.4.1, on both sidekiq 6.5.12 and
7.3.9 (repro script in the issue).

This PR makes `start` take the already-expanded list from where each Sidekiq version
keeps it, without deduping:

- **Sidekiq 6.x**: `config[:queues]` (expanded by the CLI) — as 4.3.2/4.4.0 did.
- **Sidekiq 7.x**: `capsule.queues` — `capsule.config[:queues]` holds the raw
  `[[name, weight], …]` YAML shape (`Config#merge!` is a plain hash delegate), so the
  previous `map { queue.first }` dropped the weights there too. Strictness now comes
  from `capsule.mode == :strict`, since the Sidekiq 7 CLI never sets
  `config[:strict]` — this also fixes strict (unweighted) configs wrongly getting
  `weighted_order!` on 7.

The per-fetch dedup that BRPOP needs already happens downstream (`shuffle.uniq` in
`weighted_order!`, `@queues.uniq!` in `strict_order!`), where it is lossless because
the weight information has already been converted into list position.
@StevenJL StevenJL changed the title Fixes https://github.com/deanpcmad/sidekiq-limit_fetch/issues/165 Fixes bug where queue weights are not honored anymore Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sidekiq-limit_fetch silently stops honoring Sidekiq queue weights

1 participant