Repository navigation
Dispatch the highest priority tasks first in the executor - #70942
pierrejeambrun merged 1 commit into
Conversation
SameerMesiah97
left a comment
There was a problem hiding this comment.
This makes sense. The documentation has long stated that larger priority_weight values have higher priority, so this appears to correct an implementation bug. Below is the relevant section from the documentation for others who will review this PR:
Priority Weights
================
``priority_weight`` defines priorities in the executor queue. The default ``priority_weight`` is ``1``, and can be
bumped to any integer; larger numbers mean higher priority.
Moreover, each task has a true ``priority_weight`` that is calculated based on its
``weight_rule`` which defines the weighting method used for the effective total priority weight of the task.
Below are the weighting methods. By default, Airflow's weighting method is ``downstream``.
CI still needs to be triggered though.
o-nikolas
left a comment
There was a problem hiding this comment.
Looks like a legitimate regression, nice spot. I'm not sure this needs a news fragment but it is a user facing bug so I don't mind if we keep it.
fd454e3 to
5bfd6be
Compare
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
Backport successfully created: v3-3-testNote: As of Merging PRs targeted for Airflow 3.X In matter of doubt please ask in #release-management Slack channel.
|
…#70942) (cherry picked from commit 316dc6d) Co-authored-by: Ignacio Paricio <[email protected]>
…#70942) (#71715) (cherry picked from commit 316dc6d) Co-authored-by: Ignacio Paricio <[email protected]>
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
…#70942) (#71715) (cherry picked from commit 316dc6d) Co-authored-by: Ignacio Paricio <[email protected]>
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
The rebase onto main brought in apache#70942, which flipped queued-task dispatch to highest priority_weight first, but the unified sort_key still sorted ascending and would have silently reverted that fix.
BaseExecutorsorts its queued tasks bypriority_weightascending, then dispatches from the front of that list. So when more tasks are queued than there are open slots, the lowest priority tasks are the ones sent to workers, and the highest priority ones are held back.For example, with weights 1, 5 and 10 and one slot freeing up per loop, they run in the order 1, 5, 10; the most important task runs last.
It also does not even out over time, because the queue is re-sorted on every call.
This only affects an executor that has more queued tasks than open slots, so deployments that stay under their
parallelismceiling, or that never setpriority_weight, see no difference either way.Where it happens
In
airflow-core/src/airflow/executors/base_executor.py:How it got here
The sort and the way it is consumed used to match. They drifted apart in two steps:
fd4fd67c0f) switched the sort from descending to ascending and, in the same commit, changedsorted_queue.pop(0)tosorted_queue.pop(). An ascending list popped from the back still gives the highest priority first, so this was correct, and O(1) instead of O(n).9fa13c82ff) refactoredtrigger_tasksto support callback workloads and replaced thatpop()with the front-to-back loop above. The sort was left ascending.What this PR does:
base_executor.py: sorts descending again, and notes on the method that consumers read from the front.test_base_executor.py: adds a test with three weights and fewer open slots than tasks. The existing tests all run with more slots than tasks, so none of them reach the truncating branch.Was generative AI tooling used to co-author this PR?
Used to trace the ordering back through the history of the two commits above, and to check that nothing else in the repo overrides the sort or depends on it being ascending.