Repository navigation
Pin the statement budget for persisting Dag parse results - #71720
Merged
Merged
Conversation
The Dag processor's manager issues these statements once per parsed file, and how many was written down nowhere, so a change could add round trips to that path unnoticed. Measure it: a call costs 10 statements per file plus 3 per Dag the file defines, and a sweep pays that fixed price once per persistence call -- currently one call per file. Those counts are calibrated against Postgres, and the tests carrying them are marked for it, since statement counts differ by dialect. The sweep cost is measured through _collect_results and derives both prices from its own measurements, so it carries no dialect-specific number, runs on any backend, and tracks whatever strategy the manager uses. Timing this proved unreliable: on a throttled single-core container, repeat runs of identical code vary by more than a third, far larger than the savings under consideration. Counting statements is exact.
Airflow's only stated rule for test layout is that a test file mirrors its source module, so a budget measured on dag_processing/manager.py belongs in test_manager.py. Kept apart, it also had to grow its own copy of the finished-processor fixture the manager's test class already provides.
ephraimbuddy
force-pushed
the
parse-result-query-budget
branch
from
August 19, 2026 18:37
bd35a7e to
c05c7ad
Compare
jedcunningham
approved these changes
Aug 20, 2026
1 task done
1 task done
ephraimbuddy
added a commit
to astronomer/airflow
that referenced
this pull request
Aug 25, 2026
The budget pinned in apache#71720 exists so a change to what persistence costs has to move a number and account for it. This one does: a file that parses cleanly no longer looks up import errors it has none of, so every call is a statement cheaper.
ephraimbuddy
added a commit
that referenced
this pull request
Aug 26, 2026
* Cut the per-file cost of persisting Dag parse results The Dag processor's manager persists parse results one file at a time, and on small deployments that process is the CPU bottleneck. Two costs were paid there for every parsed file. Import errors were read by loading the whole import_error table, even for files that had none. The lookup is now scoped to the keys being written. The table has no index on (bundle_name, filename), so this saves materialising every row rather than the scan itself. The serialized Dag was hashed twice per write, once for change detection and again in the model constructor, and hashing re-sorts and re-encodes the whole structure. The compressed-storage test parametrization never ran, because the module binds that flag at import. It is made real here, since this change moves code into that branch. From @seanmuth's investigation of the Airflow 2-to-3 dag-processor CPU regression: github.com/seanmuth/af2-af3-scheduler-cpu-repro. This is two of the smaller levers; the per-sweep result batching is left for follow-up. * Say less around the bounded import-error lookup Review feedback: the comments explained more than the code needed, and falling back with `or` reads better than a None check for a value that is always an md5 digest when it is set at all. * Drop the per-call statement price the bounded lookup saves The budget pinned in #71720 exists so a change to what persistence costs has to move a number and account for it. This one does: a file that parses cleanly no longer looks up import errors it has none of, so every call is a statement cheaper. * Pin what a file reporting an import error costs to persist The budget covered only files that parse cleanly, which is the half of the call this change makes cheaper. The half that still looks its errors up was unpriced, so nothing would notice a round trip appearing there.
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.
The Dag processor's manager issues these statements once per parsed file, and how many was written down nowhere, so a change could add round trips to that path unnoticed.
Measure it: a call costs 10 statements per file, plus 3 per Dag while the serialized Dag is left alone, or 5 per Dag once the hash has moved and [core] min_serialized_dag_update_interval has lapsed, so the call rewrites it. Both paths are pinned, because a change that adds a round trip to the write path would otherwise hide behind the cheaper one. A sweep pays the fixed price once per persistence call -- currently one call per file. Those counts are calibrated against Postgres, and the tests carrying them are marked for it, since statement counts differ by dialect.
The sweep cost is measured through _collect_results and derives both prices from its own measurements, so it carries no dialect-specific number, runs on any backend, and tracks whatever strategy the manager uses.
Timing this proved unreliable: on a throttled single-core container, repeat runs of identical code vary by more than a third, far larger than the savings under consideration. Counting statements is exact.
Was generative AI tooling used to co-author this PR?