Skip to content

[v3-4-test] Fix scheduler memory spike when a Dag run has a large conf (#73907) - #76252

Merged
shahar1 merged 1 commit into
apache:v3-4-testfrom
shahar1:backport-73907-v3-4-test
Nov 6, 2026
Merged

shahar1 merged 1 commit into
apache:v3-4-testfrom
shahar1:backport-73907-v3-4-test

Conversation

@shahar1

@shahar1 shahar1 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Backport of #73907 to v3-4-test.

The cherry-pick conflicted only in DagRun.fetch_task_instances: v3-4-test does not have the columns parameter from main, so the backport keeps the existing query and adds .defer(DagRun.conf) to its joinedload(TI.dag_run). The _get_ready_tis change and the two tests apply unchanged.

The two new tests in airflow-core/tests/unit/models/test_dagrun.py fail without the change and pass with it.

(cherry picked from commit ce01a73)


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

apache#73907)

* Add tests for the run conf loaded per task instance when scheduling

TaskInstance.dag_run is a joined eager load, so a task-instance query
that also selects dag_run.conf returns and decodes one copy of the conf
per row. A scheduling pass does that twice: fetch_task_instances reads
every task instance of the run, and _get_ready_tis re-reads the ones
still waiting on their upstreams. A large conf on a run with many
mapped task instances multiplies scheduler memory this way.

* Fix scheduler memory spike when a Dag run has a large conf

TaskInstance.dag_run is a joined eager load, so every row of a
task-instance query also carries the run's conf. The scheduler fetches
all task instances of each running Dag run on every loop, and re-reads
the ones still waiting on their upstreams, so a large conf was decoded
once per task instance: a 1 MB conf on a run with 500 mapped task
instances took the scheduler from 150 MB to over 3 GB.

Neither query needs the conf up front: the few callers that read it
can load it on access, and the re-check only compares states.

(cherry picked from commit ce01a73)
@shahar1 shahar1 added the use fork ci Committer override: run CI in the author's fork instead of project CI. label Nov 4, 2026
@shahar1
shahar1 force-pushed the backport-73907-v3-4-test branch from a0f4c10 to 5ae0532 Compare November 4, 2026 18:48
@github-actions github-actions Bot added the fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Fork CI: green. CI for the latest commit passed in your fork. The pull request is ready for maintainer review.

Pull requests from contributors run their CI in the contributor's own fork. GitHub Actions is free and has no minute limit on public forks, while the CI capacity of the Apache Software Foundation is shared by every ASF project and is finite.

Latest run: https://github.com/shahar1/airflow/actions/runs/41890838634

How this works: fork CI for external contributors.


This comment was posted automatically by the fork CI monitor from templates drafted with an AI-assisted tool, so it may contain mistakes. An Apache Airflow maintainer, a real person, will review the pull request once its fork CI is green. Why the first pass is automated.

@github-actions github-actions Bot added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Nov 4, 2026
@shahar1
shahar1 merged commit a264c38 into apache:v3-4-test Nov 6, 2026
30 checks passed
@shahar1
shahar1 deleted the backport-73907-v3-4-test branch November 6, 2026 07:05
@github-actions github-actions Bot added this to the Airflow 3.4.1 milestone Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.4.1 based on: bug fix merged to version branch
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

vatsrahul1001 pushed a commit that referenced this pull request Nov 9, 2026
#73907) (#76252)

* Add tests for the run conf loaded per task instance when scheduling

TaskInstance.dag_run is a joined eager load, so a task-instance query
that also selects dag_run.conf returns and decodes one copy of the conf
per row. A scheduling pass does that twice: fetch_task_instances reads
every task instance of the run, and _get_ready_tis re-reads the ones
still waiting on their upstreams. A large conf on a run with many
mapped task instances multiplies scheduler memory this way.

* Fix scheduler memory spike when a Dag run has a large conf

TaskInstance.dag_run is a joined eager load, so every row of a
task-instance query also carries the run's conf. The scheduler fetches
all task instances of each running Dag run on every loop, and re-reads
the ones still waiting on their upstreams, so a large conf was decoded
once per task instance: a 1 MB conf on a run with 500 mapped task
instances took the scheduler from 150 MB to over 3 GB.

Neither query needs the conf up front: the few callers that read it
can load it on access, and the re-check only compares states.

(cherry picked from commit ce01a73)

Co-authored-by: Lucas Pimentel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork ci required Gated by AIP-120: CI must pass in the contributor's fork. Managed by the fork CI reconciler. ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. use fork ci Committer override: run CI in the author's fork instead of project CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants