Reduce scheduler memory for asset-triggered Dag runs#69849
Open
viiccwen wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
cc @Lee-W, @jason810496. ✨🙌 |
Lee-W
reviewed
Jul 14, 2026
Lee-W
left a comment
Member
There was a problem hiding this comment.
Thanks! I remember we did something similar elsewhere. the overall idea looks good to me
Large asset event windows can exhaust scheduler memory because every event, including JSON metadata, is materialized as an ORM object before its Dag run association is persisted. Signed-off-by: viiccwen <vicwen@apache.org>
Asset-triggered Dag runs should retain the established event selection order while avoiding ORM materialization. Scoping the ordering to scheduler association creation avoids adding sort costs to every consumed_asset_events relationship load. Signed-off-by: viiccwen <vicwen@apache.org>
c250d56 to
bb68de6
Compare
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.
Description
closes #69848
Asset-triggered Dag run creation currently materializes every matching
AssetEventORM object, including its JSON metadata, before writing the Dag run association rows. Large event windows can therefore cause scheduler memory spikes far beyond the raw payload size.This change writes the association rows with a server-side
INSERT ... SELECTwhile preserving the existing event predicates, transaction boundary, exact event membership, and relationship behavior.Scheduler-side
AssetEventORM and JSON payload materialization drops from O(events) to approximately O(1). The database still performs O(events) work to select event IDs and persist one association row per event; this change moves that set operation out of Python rather than eliminating it.The partitioned-asset path uses the same set-based association helper. No schema or configuration change is needed.
Benchmark
The benchmark invokes the real scheduler path on SQLite, PostgreSQL, and MySQL with a 512-byte JSON
payload per event. Setup is outside the measured interval.
The 1,000-event result includes first-call and tracing warm-up overhead.
Notes
consumed_asset_event_countis designed for logging, can discuss leave it or not.Was generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.