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

Remove the 2x, further comments

This commit is contained in:
Mike Perham 2018-07-20 10:46:29 -07:00
parent 8a589d68fe
commit ea3beeef40

View file

@ -103,27 +103,27 @@ module Sidekiq
# #
# So in N*M second timespan, we want each process to schedule once. The basic loop is: # So in N*M second timespan, we want each process to schedule once. The basic loop is:
# #
# * sleep # a random amount within that N*M timespan # * sleep a random amount within that N*M timespan
# * wake up, schedule # * wake up and schedule
# #
# There are pathological edge cases: # We want to avoid one edge case: imagine a set of 2 processes, scheduling every 5 seconds,
# # so N*M = 10. Each process decides to randomly sleep 8 seconds, now we've failed to meet
# Imagine a set of 4 processes, scheduling every 5 seconds, so N*M = 20. Each process # that 5 second average. Thankfully each schedule cycle will sleep randomly so the next
# decides to randomly sleep 18 seconds, now we've failed to meet that 5 second average. # iteration could see each process sleep for 1 second, undercutting our average.
# Thankfully each schedule cycle will sleep randomly so the next iteration could see each
# process sleep for 1 second, undercutting our average.
# #
# So below 10 processes, we special case and ensure the processes sleep closer to the average. # So below 10 processes, we special case and ensure the processes sleep closer to the average.
# As we run more processes, the scheduling interval average should approach the desired # In the example above, each process should schedule every 10 seconds on average. We special
# amount. # case smaller clusters to add 50% so they would sleep somewhere between 5 and 15 seconds.
# As we run more processes, the scheduling interval average will approach an even spread
# between 0 and poll interval so we don't need this artifical boost.
# #
if process_count < 10 if process_count < 10
# For small clusters, # calculates a random interval that is ±50% the desired average. # For small clusters, calculate a random interval that is ±50% the desired average.
poll_interval_average * rand + poll_interval_average.to_f / 2 poll_interval_average * rand + poll_interval_average.to_f / 2
else else
# With 10+ processes, we should have enough randomness to get decent polling # With 10+ processes, we should have enough randomness to get decent polling
# across the entire timespan # across the entire timespan
poll_interval_average * rand * 2 poll_interval_average * rand
end end
end end