Skip to content

Commit

Permalink
Have Poller#random_poll_interval code memoize the process count.
Browse files Browse the repository at this point in the history
Poller#random_poll_interval right now grabs a process count which SSCANs 'processes' and then HGETs all the results. This can be prohibitive. sidekiq#4882 may get merged in to fix in future versions.
  • Loading branch information
jonhyman committed Apr 22, 2021
1 parent 2605fc0 commit 5915072
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/sidekiq/scheduled.rb
Expand Up @@ -116,8 +116,10 @@ def random_poll_interval
# 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
# Memoize the process count to avoid calling SCARD/HGET on all the processes everytime #wait is called
# since there may be a lot of processes online.
@process_count ||= process_count
if @process_count < 10
# For small clusters, calculate a random interval that is ±50% the desired average.
poll_interval_average * rand + poll_interval_average.to_f / 2
else
Expand Down

0 comments on commit 5915072

Please sign in to comment.