Skip to content

Commit

Permalink
Minimize scheduler load on Redis, closes #4882
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed May 3, 2021
1 parent da15276 commit ed73ed0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes.md
Expand Up @@ -2,6 +2,11 @@

[Sidekiq Changes](https://github.com/mperham/sidekiq/blob/master/Changes.md) | [Sidekiq Pro Changes](https://github.com/mperham/sidekiq/blob/master/Pro-Changes.md) | [Sidekiq Enterprise Changes](https://github.com/mperham/sidekiq/blob/master/Ent-Changes.md)

HEAD
---------

- Minimize scheduler load on Redis at scale [#4882]

6.2.1
---------

Expand Down
8 changes: 7 additions & 1 deletion lib/sidekiq/scheduled.rb
Expand Up @@ -49,6 +49,7 @@ def initialize
@sleeper = ConnectionPool::TimedStack.new
@done = false
@thread = nil
@count_calls = 0
end

# Shut down this instance, will pause until the thread is dead.
Expand Down Expand Up @@ -152,8 +153,13 @@ def scaled_poll_interval
end

def process_count
pcount = Sidekiq::ProcessSet.new.size
# The work buried within Sidekiq::ProcessSet#cleanup can be
# expensive at scale. Cut it down by 90% with this counter.
# NB: This method is only called by the scheduler thread so we
# don't need to worry about the thread safety of +=.
pcount = Sidekiq::ProcessSet.new(@count_calls % 10 == 0).size
pcount = 1 if pcount == 0
@count_calls += 1
pcount
end

Expand Down

0 comments on commit ed73ed0

Please sign in to comment.