Threshold across multiple workers & web question
Closed this issue · 3 comments
Hi @ixti
We want to set up job limitation per second in out project.
Could you please clarify how threshold -> limit works across multiple sidekiq instances/workers?
Also I added
require "sidekiq/throttled/web"
but I cannot see classes with sidekiq_throttle
configuration in Throttled sidekiq tab
Maybe we are doing something wrong?
Thanks
Sidekiq Throttled tab shows only throttling known to the process that runs sidekiq-web. In other words in Rails development environment, unless you eager-load classes - you won't see anything. Also Throttled page does not shows classes with :key_suffix => proc { }
config option.
Threshold limitation works perfectly across multiple sidekiq instances/workers. You just need to make sure that all your instances clock are in sync as Time.now
is used for timestamping (it will be possible to use Redis' own timestamp for that in future - at the moment I'm not sure about the best way of dealing that). So if you have threshold limit of 10 jobs per 1 second, that means no more than 10 jobs will be processed in every 1 second.
Hi there @ixti, thanks for the gem! Just to clarify your answer above, if I set a threshold of 10 jobs per 1 second, then it doesn't matter if I have 1 sidekiq process or 10 sidekiq processes, only 10 jobs will be processed per minute? In other words, the limits are NOT per-process?
@shannondoah sorry for delay with answer. I'm glad you like it. :D
You are correct. Regardless of amount of sidekiq processes, by default, :concurrent => { :limit => 10 }
will guarantee to allow max 10 concurrent jobs regardless of amount of sidekiq processes. Same for :threshold
. If you want to make limitation it per-process, you can use key_suffix
:
# see: https://ruby-doc.org/stdlib-2.5.0/libdoc/English/rdoc/English.html
require "English"
class MyWorker
include Sidekiq::Worker
include Sidekiq::Throttled::Worker
sidekiq_throttle({
:concurrent => {
:limit => 10,
:key_suffix => proc { $PROCESS_ID }
}
})
# ...
end