fix(scheduler): defer loading dag_run.conf to avoid memory spike with large run config (#71267) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #71322
Open
waterWang wants to merge 2 commits into
Conversation
… large run config When a DAG with dynamic task mapping is triggered with a large run config (512KB–2MB JSON), the scheduler's critical section query eagerly loads the full dag_run row—including the conf column—for every task instance. Since 500+ mapped task instances share one dag_run, the joined SQL result set carries ~1 GiB of redundant conf data, causing a 5–6× scheduler memory spike (apache#71267). Fix: add .defer(DagRun.conf) to the eager-load chain. The scheduler never reads dag_run.conf in the critical section, so deferring it eliminates the bloat while keeping all other columns and the secondary selectinload of created_dag_version available.
… large run config
Contributor
|
Thanks @waterWang ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a DAG with dynamic task mapping is triggered with a large run config (512KB–2MB JSON), the scheduler memory spikes by 5–6× during scheduling of the dynamic tasks. Once the dagrun completes, the memory returns to normal.
Reported in #71267.
Root Cause
The scheduler's critical section query at
_executable_task_instances_to_queuedusesjoinedload(TI.dag_run)(line 808), which eagerly loads the full dag_run row — including theconfcolumn — for every task instance in the SQL result set.When 500+ mapped task instances all share the same dag_run, the joined SQL result set carries the 2MiB conf column 500+ times. This results in approximately 1 GiB of redundant conf data being transferred from the database and materialized in Python memory, causing the memory spike.
Fix
Add
.defer(DagRun.conf)to the eager-load chain. The scheduler never readsdag_run.confin the critical section, so deferring it eliminates the bloat while keeping all other columns and the secondaryselectinloadofcreated_dag_versionavailable.Verification
defercorrectly excludes theconfcolumn from the SELECT statementtest_executable_task_instances_no_per_ti_queriesstill passes (no N+1 regression)Closes #71267