-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix performance issue when deleting from large sets
- Loading branch information
Showing
11 changed files
with
93 additions
and
59 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
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
20 changes: 10 additions & 10 deletions
20
lib/sidekiq_unique_jobs/lua/shared/_delete_from_queue.lua
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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
local function delete_from_queue(queue, digest) | ||
local per = 50 | ||
local total = redis.call("LLEN", queue) | ||
local index = 0 | ||
local result = nil | ||
local total = redis.call("LLEN", queue) | ||
local per = 50 | ||
|
||
for index = 0, total, per do | ||
local items = redis.call("LRANGE", queue, index, index + per - 1) | ||
|
||
while (index < total) do | ||
local items = redis.call("LRANGE", queue, index, index + per -1) | ||
if #items == 0 then | ||
break | ||
end | ||
|
||
for _, item in pairs(items) do | ||
if string.find(item, digest) then | ||
redis.call("LREM", queue, 1, item) | ||
result = item | ||
break | ||
|
||
return item | ||
end | ||
end | ||
index = index + per | ||
end | ||
return result | ||
|
||
return nil | ||
end |
30 changes: 20 additions & 10 deletions
30
lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua
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 |
---|---|---|
@@ -1,19 +1,29 @@ | ||
local function delete_from_sorted_set(name, digest) | ||
local per = 50 | ||
local total = redis.call("zcard", name) | ||
local index = 0 | ||
local result | ||
local score = redis.call("ZSCORE", "uniquejobs:digests", digest) | ||
local total = redis.call("ZCARD", name) | ||
local per = 50 | ||
|
||
for offset = 0, total, per do | ||
local items | ||
|
||
if score then | ||
items = redis.call("ZRANGE", name, score, "+inf", "BYSCORE", "LIMIT", offset, per) | ||
else | ||
items = redis.call("ZRANGE", name, offset, offset + per -1) | ||
end | ||
|
||
if #items == 0 then | ||
break | ||
end | ||
|
||
while (index < total) do | ||
local items = redis.call("ZRANGE", name, index, index + per -1) | ||
for _, item in pairs(items) do | ||
if string.find(item, digest) then | ||
redis.call("ZREM", name, item) | ||
result = item | ||
break | ||
|
||
return item | ||
end | ||
end | ||
index = index + per | ||
end | ||
return result | ||
|
||
return nil | ||
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
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
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