-
-
Notifications
You must be signed in to change notification settings - Fork 9
Set queue wake event when executor is not full anymore #48
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
Set queue wake event when executor is not full anymore #48
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 24_4 #48 +/- ##
==========================================
+ Coverage 71.26% 71.51% +0.25%
==========================================
Files 55 55
Lines 2899 2907 +8
==========================================
+ Hits 2066 2079 +13
+ Misses 833 828 -5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a queue polling issue in chancy where jobs would unnecessarily wait for the polling_interval when using queues with concurrency=1. The main change replaces the original wake event mechanism that wasn't working properly with a new approach that wakes the queue when the executor transitions from full to having available slots.
- Refactors the job polling logic to use
executor.free_slotsinstead of calculating concurrency manually - Implements a new wake event mechanism in the AsyncExecutor that triggers when a task completes and the executor was previously full
- Removes the previous wake event logic that was based on the number of jobs fetched
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| chancy/worker.py | Simplifies job polling logic by using executor.free_slots and removes the ineffective wake event mechanism |
| chancy/executors/asyncex.py | Adds a custom task completion callback that sets the wake event when executor transitions from full to available |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| task.add_done_callback(self._on_task_done) | ||
|
|
||
| def _on_task_done(self, task): | ||
| if self.free_slots == 0: |
Copilot
AI
Aug 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition self.free_slots == 0 is checked before removing the completed job from self.jobs, so it will always be false when a job completes. The check should be self.free_slots == 1 to detect when the executor was exactly full before the job completed.
| if self.free_slots == 0: | |
| if self.free_slots == 1: |
|
Hey @TkTech, could this change be part of O.24.4 release as well ? thanks ! |
151b3c3 to
5f2224b
Compare
|
This is an interesting one. We want to keep the worker busy, but we also do not want to necessarily poll every time the executor has cleared a job. That could be an incredible number of queries, especially on something like an async executor with ~1000 concurrent tasks. I added a regression test for this in #49, but still thinking over what the right fix is. I think the "right" fix might be to make "eager polling" an optional setting, which causes the executor to aggressively fill itself. I plan on releasing #49 tomorrow with support for this. |
True ! An optional setting might be good, so user can decide to enable it when concurrency is low and disable it when concurrency is high. |
Hey @TkTech,
Running chancy with queues configured with concurrency=1, I have observed that polling next job waits for
polling_interval.The fix we added to set the queue wake event on condition
len(jobs) == maximum_jobs_to_pollwas not working. I have a fix to make it work for asyncex if you don't mind to have a look.Thanks !