-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve reaper performance under heavy load (#666)
* Improve reaper performance under heavy load Closes #663 Signed-off-by: mhenrixon <[email protected]> * Mandatory linter commit
- Loading branch information
Showing
3 changed files
with
25 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ module Orphans | |
# | ||
# @author Mikael Henriksson <[email protected]> | ||
# | ||
# rubocop:disable Metrics/ClassLength | ||
class RubyReaper < Reaper | ||
# | ||
# @return [String] the suffix for :RUN locks | ||
|
@@ -54,13 +55,27 @@ def call | |
# | ||
# @return [Array<String>] an array of orphaned digests | ||
# | ||
def orphans | ||
conn.zrevrange(digests.key, 0, -1).each_with_object([]) do |digest, memo| | ||
next if belongs_to_job?(digest) | ||
def orphans # rubocop:disable Metrics/MethodLength | ||
page = 0 | ||
per = reaper_count * 2 | ||
orphans = [] | ||
results = conn.zrange(digests.key, page * per, (page + 1) * per) | ||
|
||
memo << digest | ||
break memo if memo.size >= reaper_count | ||
while results.size.positive? | ||
results.each do |digest| | ||
next if belongs_to_job?(digest) | ||
|
||
orphans << digest | ||
break if orphans.size >= reaper_count | ||
end | ||
|
||
break if orphans.size >= reaper_count | ||
|
||
page += 1 | ||
results = conn.zrange(digests.key, page * per, (page + 1) * per) | ||
end | ||
|
||
orphans | ||
end | ||
|
||
# | ||
|
@@ -211,5 +226,6 @@ def in_sorted_set?(key, digest) | |
conn.zscan_each(key, match: "*#{digest}*", count: 1).to_a.any? | ||
end | ||
end | ||
# rubocop:enable Metrics/ClassLength | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters