Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dramatically decreases the time spent listing queues #120

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

robacarp
Copy link
Collaborator

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 with zadd and zrangeby, 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:

  • enqueue another job with a mosquito version after this commit
  • manually add the queue to the list at the key 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.

One of the most frequent commands issued to the mosquito redis backend is strongly frowned upon by the redis community.

[`keys`](https://redis.io/commands/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` with `zadd` and `zrangeby`, 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:

- enqueue another job with a mosquito version after this commit
- manually add the queue to the list at the key `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.
@robacarp robacarp merged commit 39ddc84 into master Oct 11, 2023
2 of 3 checks passed
@robacarp robacarp deleted the queue_list_performance branch October 11, 2023 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant