Skip to content

[v3-3-test] Release DB connection before deserializing DAGs in grid structure endpoint (#69832) - #71626

Merged
pierrejeambrun merged 1 commit into
v3-3-testfrom
backport-b278b62-v3-3-test
Aug 17, 2026
Merged

pierrejeambrun merged 1 commit into
v3-3-testfrom
backport-b278b62-v3-3-test

Conversation

@github-actions

Copy link
Copy Markdown
Contributor
  • Release DB connection before deserializing DAGs in grid structure endpoint

get_dag_structure (GET /ui/grid/structure/{dag_id}) streamed historical
SerializedDagModel rows with a yield_per server-side cursor while running
CPU-bound serdag.dag deserialization and task-group merging between fetches.
That keeps the read transaction — and, under PgBouncer transaction pooling, the
pooled server connection — pinned for the entire render of a large DAG.

At scale this holds connections open for minutes, exhausting the PgBouncer pool
and starving task-instance heartbeats, contributing to the contention tracked in
#65712.

Materialize the (page-bounded) historical serialized DAGs, detach them, and
commit the read transaction so the connection returns to the pool before the
deserialization/merge. SerializedDagModel.dag only reads the already-loaded
data column, so it works on detached instances.

This mirrors the per-unit session-release pattern already applied to the
streaming ti_summaries endpoint in #65010.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

  • Batch historical serdag loading to keep memory bounded

Address review: instead of materializing all historical SerializedDagModel
rows at once (which regressed the yield_per=5 memory profile), fetch their ids
and process them in batches of 5, each batch loaded and detached in its own
short-lived session that is closed before the batch is deserialized.

This keeps peak memory bounded to one batch (matching the previous behaviour)
while still releasing the DB connection during the CPU-bound deserialization.
Also drop the newsfragment per review.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

  • Address review: trim comment, drop unnecessary order_by, use session.close()
  • Comment above serdag_id_query was too verbose for a simple query; the
    rationale belongs in the commit message. Trimmed per dstandish's suggestion.
  • Dropped .order_by(SerializedDagModel.id): the original code had no explicit
    ordering, and _merge_node_dicts is sensitive to processing order for nodes
    that differ across historical Dag versions, so this restores exact prior
    behavior instead of introducing an unreviewed ordering guarantee.
  • Replaced session.commit() with session.close(): this session has done no
    writes (pure read), so close() is the more accurate call and, per review,
    reads clearer while releasing the connection the same way.

(cherry picked from commit b278b62)

Co-authored-by: Sean Muth [email protected]
Co-authored-by: Claude Opus 4.8 (1M context) [email protected]

…tructure endpoint (#69832)

* Release DB connection before deserializing DAGs in grid structure endpoint

`get_dag_structure` (`GET /ui/grid/structure/{dag_id}`) streamed historical
`SerializedDagModel` rows with a `yield_per` server-side cursor while running
CPU-bound `serdag.dag` deserialization and task-group merging between fetches.
That keeps the read transaction — and, under PgBouncer transaction pooling, the
pooled server connection — pinned for the entire render of a large DAG.

At scale this holds connections open for minutes, exhausting the PgBouncer pool
and starving task-instance heartbeats, contributing to the contention tracked in
#65712.

Materialize the (page-bounded) historical serialized DAGs, detach them, and
commit the read transaction so the connection returns to the pool *before* the
deserialization/merge. `SerializedDagModel.dag` only reads the already-loaded
`data` column, so it works on detached instances.

This mirrors the per-unit session-release pattern already applied to the
streaming `ti_summaries` endpoint in #65010.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Add newsfragment for #69832

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Batch historical serdag loading to keep memory bounded

Address review: instead of materializing all historical SerializedDagModel
rows at once (which regressed the yield_per=5 memory profile), fetch their ids
and process them in batches of 5, each batch loaded and detached in its own
short-lived session that is closed before the batch is deserialized.

This keeps peak memory bounded to one batch (matching the previous behaviour)
while still releasing the DB connection during the CPU-bound deserialization.
Also drop the newsfragment per review.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Address review: trim comment, drop unnecessary order_by, use session.close()

- Comment above serdag_id_query was too verbose for a simple query; the
  rationale belongs in the commit message. Trimmed per dstandish's suggestion.
- Dropped .order_by(SerializedDagModel.id): the original code had no explicit
  ordering, and _merge_node_dicts is sensitive to processing order for nodes
  that differ across historical Dag versions, so this restores exact prior
  behavior instead of introducing an unreviewed ordering guarantee.
- Replaced session.commit() with session.close(): this session has done no
  writes (pure read), so close() is the more accurate call and, per review,
  reads clearer while releasing the connection the same way.

---------
(cherry picked from commit b278b62)

Co-authored-by: Sean Muth <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@pierrejeambrun
pierrejeambrun merged commit 728605c into v3-3-test Aug 17, 2026
160 of 169 checks passed
@pierrejeambrun
pierrejeambrun deleted the backport-b278b62-v3-3-test branch August 17, 2026 11:00
@github-actions github-actions Bot added this to the Airflow 3.3.2 milestone Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.3.2 based on: 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 Sep 7, 2026
…tructure endpoint (#69832) (#71626)

* Release DB connection before deserializing DAGs in grid structure endpoint

`get_dag_structure` (`GET /ui/grid/structure/{dag_id}`) streamed historical
`SerializedDagModel` rows with a `yield_per` server-side cursor while running
CPU-bound `serdag.dag` deserialization and task-group merging between fetches.
That keeps the read transaction — and, under PgBouncer transaction pooling, the
pooled server connection — pinned for the entire render of a large DAG.

At scale this holds connections open for minutes, exhausting the PgBouncer pool
and starving task-instance heartbeats, contributing to the contention tracked in
#65712.

Materialize the (page-bounded) historical serialized DAGs, detach them, and
commit the read transaction so the connection returns to the pool *before* the
deserialization/merge. `SerializedDagModel.dag` only reads the already-loaded
`data` column, so it works on detached instances.

This mirrors the per-unit session-release pattern already applied to the
streaming `ti_summaries` endpoint in #65010.



* Add newsfragment for #69832



* Batch historical serdag loading to keep memory bounded

Address review: instead of materializing all historical SerializedDagModel
rows at once (which regressed the yield_per=5 memory profile), fetch their ids
and process them in batches of 5, each batch loaded and detached in its own
short-lived session that is closed before the batch is deserialized.

This keeps peak memory bounded to one batch (matching the previous behaviour)
while still releasing the DB connection during the CPU-bound deserialization.
Also drop the newsfragment per review.



* Address review: trim comment, drop unnecessary order_by, use session.close()

- Comment above serdag_id_query was too verbose for a simple query; the
  rationale belongs in the commit message. Trimmed per dstandish's suggestion.
- Dropped .order_by(SerializedDagModel.id): the original code had no explicit
  ordering, and _merge_node_dicts is sensitive to processing order for nodes
  that differ across historical Dag versions, so this restores exact prior
  behavior instead of introducing an unreviewed ordering guarantee.
- Replaced session.commit() with session.close(): this session has done no
  writes (pure read), so close() is the more accurate call and, per review,
  reads clearer while releasing the connection the same way.

---------
(cherry picked from commit b278b62)

Co-authored-by: Sean Muth <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants