Repository navigation
[v3-3-test] Release DB connection before deserializing DAGs in grid structure endpoint (#69832) - #71626
Merged
Conversation
…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
marked this pull request as ready for review
August 14, 2026 16:20
pierrejeambrun
requested review from
bugraoz93,
choo121600,
ephraimbuddy,
henry3260,
jason810496,
pierrejeambrun,
rawwar and
shubhamraj-git
as code owners
August 14, 2026 16:20
henry3260
approved these changes
Aug 15, 2026
pierrejeambrun
approved these changes
Aug 17, 2026
Contributor
Author
|
Hi maintainer, this PR was merged without a milestone set.
|
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]>
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.
get_dag_structure(GET /ui/grid/structure/{dag_id}) streamed historicalSerializedDagModelrows with ayield_perserver-side cursor while runningCPU-bound
serdag.dagdeserialization 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.dagonly reads the already-loadeddatacolumn, so it works on detached instances.This mirrors the per-unit session-release pattern already applied to the
streaming
ti_summariesendpoint in #65010.Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
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]
rationale belongs in the commit message. Trimmed per dstandish's suggestion.
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.
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]