Sidekiq: Changing queues options to hash instead of array

Created on 29 Dec 2017  路  3Comments  路  Source: mperham/sidekiq

Ruby version: All
Sidekiq - Free, all versions

Do you ever try to add one queue with 10000000000 weight?
You will probably run out of memory...

I propose to change options[:queues] from ['queue', 'queue', 'queue'...repeat n times] to { 'queue' => n }

Sidekiq does queues.shuffle.uniq to sort queues based on weights.
This algorithm has O(N) complexity where N is sum of weights

I propose to do sorting of hash queues.to_a.sort_by { |_queue, weight| -Math.log(rand) / weight }
This math formula i found here
This algorithm has also O(N) complexity but N is number of queues, which is usually much less then sum of weights.

Comparing results
Benchmarks

Old algorithm is still faster for small weights.
But if user can specify weights with two zeros, new approach will be better

What do you think about such changes, will you accept a PR?

All 3 comments

I'm not interested in this change. It's a minor issue and not worth the effort to try and fix. Don't use large weights.

Maybe this

Don't use large weights.

can be at least reflected in Advanced Options wiki?

The documentation is not meant to cover every single edge case and possible issue. If I say that, then I need to define "what is large?", why it is a problem, etc.

Was this page helpful?
0 / 5 - 0 ratings