dramatically decreases the time spent listing queues #120
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One of the most frequent commands issued to the mosquito redis backend is strongly frowned upon by the redis community.
keys
is listed as both slow and dangerous because it iterates the entire keyspace in O(n) time.This replaces
keys
when used to enumerate the list of queues that a mosquito runner should be checking. In a redis server with 10,000 stored keys, listing search queues takes 3-5ms.After replacing
keys
withzadd
andzrangeby
, listing search queues takes 0.3ms. I've chosen to use a sorted set to open up the possibility for automatically pruning the list.This change is innocuous except in the rare case that a long list of jobs have been enqueued which need to be consumed but are no longer being enqueued. In the rare possibility that use case actually exist there are two workarounds:
mosquito:queues
I considered automatically falling back to the old behavior on the contingency that no queues are found but I consider the likelihood that someone is using mosquito in a manner that would require this mitigation is tiny. The amount of effort required to mitigate the problem is small, and the amount of effort required to maintain the old behavior on some sort of fallback is significant.