Closed pacMakaveli closed 4 years ago
Right now there's no way to throttle by queue - it's on my radar, but not built-in yet. But still you can do what you want with "shared" throttling strategies. Somewhere in your bootstrapping code (initializers if you are running on rails):
Sidekiq::Throttled::Registry.add(:xbox_api, {
:concurrency => { :limit => 15 },
:threshold => { :limit => 975, :period => 1.hour }
})
Then in your jobs you will be able to:
module Network::XBOX
class GameSyncJob
include Sidekiq::Worker
include Sidekiq::Symbols
include Sidekiq::Throttled::Worker
sidekiq_options queue: :xbox_api, retry: 1, backtrace: false
sidekiq_throttle_as :xbox_api
def perform(args, options = {})
...
end
end
end
module Network::XBOX
class IdentitySyncJob
include Sidekiq::Worker
include Sidekiq::Symbols
include Sidekiq::Throttled::Worker
sidekiq_options queue: :xbox_api, retry: 1, backtrace: false
sidekiq_throttle_as :xbox_api
def perform(args, options = {})
...
end
end
end
Thanks for the help! I'll give it a go tomorrow, when I deploy some new changes and see if that does the trick.
I found this really helpful. @ixti, you cool with adding this to the readme? If so, I'd be happy to add it.
@westonplatter sure, my friend!
Does this Sidekiq::Throttled::Registry.add(:xbox_api, {....})
trick works for jobs enqueued in different queues ?
More precisely, can I make an rule for :acme_api
and share it between jobs enqueued both in :high_priority
an :low_priority
?
@Systho Yes it will work. All jobs with sidekiq_throttle_as :acme_api
will share same throttling bucket regardless of where they were enqueued to.
Hi,
So far, in development, the gem has been working great! Great! However, once I shipped the changes in production I noticed I'm pretty much reaching my API limits within minutes. I initially thought the gem throttles the queue and it applies it on all classes that use the said queue.
For example, I have 5 Workers that are using the queue.
Which gives the following:
As you can see, instead of allowing ONLY 975/hour, it allows 975/hour/class .
Question: Is there a way to limit just the queue and apply the said limit to all of its classes?
Thanks!