Skip to content

Commit 824a9ba

Browse files
committed
Use SCAN instead of KEY in startup routine
As the usage has grown we've started seeing some impact form `KEYS` being blocking and holding up the Redis instance. This is made worse by the fact than on startup many workers will be attempting this at the same time. This change moves to using the non blocking `SCAN` instead. The main concern here is that the collection of keys can change during iteration however for this use case I think this is fine as the 2 changes we can expect are: - A key goes away: this would be another startup routine removing a worker key after re-enqueuing its job so should be safe. - A key appearing: this would be a new worker coming online and should not be impacting the recovery mechanism as it should also be part of `expected_processing_queue_keys`.
1 parent 6ff4b90 commit 824a9ba

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

django_lightweight_queue/backends/reliable_redis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def startup(self, queue: QueueName) -> None:
5555
# Without this the startup process can end up racing against workers on
5656
# other machines which are validly re-populating their processing queues
5757
# as they work on jobs.
58-
current_processing_queue_keys = set(self.client.keys(pattern))
58+
current_processing_queue_keys = set(self.client.scan_iter(pattern))
5959
expected_processing_queue_keys = set(
6060
self._processing_key(queue, worker_number).encode()
6161
for worker_number in get_worker_numbers(queue)

0 commit comments

Comments
 (0)