Skip to content

Pin the statement budget for persisting Dag parse results - #71720

Merged
ephraimbuddy merged 2 commits into
apache:mainfrom
astronomer:parse-result-query-budget
Aug 20, 2026
Merged

ephraimbuddy merged 2 commits into
apache:mainfrom
astronomer:parse-result-query-budget

Conversation

@ephraimbuddy

@ephraimbuddy ephraimbuddy commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

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?
  • Yes (please specify the tool below)

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
ephraimbuddy force-pushed the parse-result-query-budget branch from bd35a7e to c05c7ad Compare August 19, 2026 18:37
@ephraimbuddy
ephraimbuddy merged commit eacefc7 into apache:main Aug 20, 2026
77 checks passed
@ephraimbuddy
ephraimbuddy deleted the parse-result-query-budget branch August 20, 2026 07:55
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants