1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Add random jitter to scheduler polling [#247]

This commit is contained in:
Mike Perham 2012-06-14 08:36:00 -07:00
parent d7ae920475
commit 82da2cd62b
3 changed files with 21 additions and 2 deletions

View file

@ -1,3 +1,9 @@
HEAD
-----------
- Add random jitter to scheduler to spread polls across POLL\_INTERVAL
window. [#247]
2.0.2
-----------

View file

@ -69,7 +69,7 @@ module Sidekiq
begin
logger.info 'Starting processing, hit Ctrl-C to stop'
@manager.start!
poller.poll!
poller.poll!(true)
sleep
rescue Interrupt
logger.info 'Shutting down'

View file

@ -18,8 +18,10 @@ module Sidekiq
SETS = %w(retry schedule)
def poll
def poll(first_time=false)
watchdog('scheduling poller thread died!') do
add_jitter if first_time
# A message's "score" in Redis is the time at which it should be processed.
# Just check Redis for the set of messages with a timestamp before now.
now = Time.now.to_f.to_s
@ -42,6 +44,17 @@ module Sidekiq
end
end
private
def add_jitter
begin
sleep(POLL_INTERVAL * rand)
rescue Celluloid::Task::TerminatedError
# Hit Ctrl-C when Sidekiq is finished booting and we have a chance
# to get here.
end
end
end
end
end