Fixes bug where queue weights are not honored anymore - #166
Open
StevenJL wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #165
Since 4.4.1,
Queues#startcalls.uniqon the queue list at boot. Sidekiq encodes a queue weight of N by repeating the queue name N times (Sidekiq::CLI#parse_queueon 6.x,Capsule#queues=on 7.x), andweighted_order!'s@queues.shuffle.uniqderives 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
starttake the already-expanded list from where each Sidekiq version keeps it, without deduping:config[:queues](expanded by the CLI) — as 4.3.2/4.4.0 did.capsule.queues—capsule.config[:queues]holds the raw[[name, weight], …]YAML shape (Config#merge!is a plain hash delegate), so the previousmap { queue.first }dropped the weights there too. Strictness now comes fromcapsule.mode == :strict, since the Sidekiq 7 CLI never setsconfig[:strict]— this also fixes strict (unweighted) configs wrongly gettingweighted_order!on 7.The per-fetch dedup that BRPOP needs already happens downstream (
shuffle.uniqinweighted_order!,@queues.uniq!instrict_order!), where it is lossless because the weight information has already been converted into list position.