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

Perform separate queries per queue assigned to worker #46

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

rosa
Copy link
Member

@rosa rosa commented Nov 21, 2023

We do this in the order specified in the worker configuration and by priority within each queue. It's still possible to specify "*", which means all queues, and in that case, the order will be only by priority. Paused queues aren't queried.

The way it works when there is more than one queue in the list is as follows. Imagine the worker is configured to run

queue1, queue2, queue3

In that order. Then:

  • Query as most N (N is the worker's capacity, or its number of idle threads) jobs from queue1. If we got at least N jobs, stop and assign these to the pool and continue querying jobs from queue1.
  • If we got fewer jobs than N, query jobs from queue2. If we reach N, stop and post those to the pool, and go back to queue1.
  • If we still have space because we haven't filled N, go on to queue3 and do the same. Then go back to queue1.

@rosa rosa marked this pull request as ready for review November 21, 2023 15:33
We do this in the order specified in the worker configuration, and
by priority within each queue. It's still possible to specify "*",
which means all queues, and in that case the order will be only by
priority. Paused queues aren't queried.

The way it works when there are more than one queue in the list is
as follows. Imagine the worker is configured to run
```
queue1, queue2, queue3
```
In that order. Then:

- Query as most N (N is the worker's capacity, or its number of idle threads)
  jobs from queue1. If we got at least N jobs, stop and assign these to the pool,
  and continue querying jobs from queue1.
- If we got fewer jobs than N, query jobs from queue2. If we reached N, stop and
  post those to the pool, and go back to queue1.
- If we still have space because we haven't filled N, go on to queue3 and do the
  same. Then go back to queue1.
@rosa rosa force-pushed the single-query-per-queue branch 2 times, most recently from 3b76e75 to b8b489e Compare November 22, 2023 12:37
@@ -12,7 +12,7 @@ def claiming(job_ids, process_id, &block)
job_data = Array(job_ids).collect { |job_id| { job_id: job_id, process_id: process_id } }

insert_all(job_data)
where(job_id: job_ids).tap do |claimed|
where(job_id: job_ids).load.tap do |claimed|
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling load here to avoid extra queries when checking the size of the relation and then loading the relation itself.

@rosa rosa force-pushed the single-query-per-queue branch 2 times, most recently from 01333c5 to 15cbf56 Compare November 22, 2023 18:18
@rosa rosa merged commit 6367062 into main Nov 22, 2023
4 checks passed
@rosa rosa deleted the single-query-per-queue branch November 22, 2023 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant