Repository navigation
Migrate Execution API GET /dags/{dag_id} to async DB session - #77206
rafaelwilliem wants to merge 1 commit into
Conversation
Release threadpool workers during database reads on GET /execution/dags/{dag_id} and project only the columns required by DagResponse instead of hydrating full DagModel and DagTag ORM entities.
|
hi @fat-catTW, is there an update in regards of this PR? |
Dev-iL
left a comment
There was a problem hiding this comment.
Review Summary
This PR migrates the Execution API GET /execution/dags/{dag_id} endpoint from synchronous SessionDep to AsyncSessionDep, with proper column projection to avoid full ORM entity hydration.
What was checked
Code review (against airflow-async-endpoints skill)
- ✅ Uses
AsyncSessionDep(existing database infrastructure) - ✅ Awaits all I/O (
session.execute,session.scalars) - ✅ No route-level commit added (transaction ownership preserved)
- ✅ Projects only the 7
DagModelcolumns required byDagResponse - ✅ Tags queried separately as names only (no
DagTagentity hydration) - ✅ No synchronous helpers called on the async path
Tests
- All 5 existing tests in
test_dags.pypass - New test
test_get_dag_does_not_hydrate_orm_entitiespasses- Uses
loaded_as_persistentlistener to verify noDagModelorDagTagentities are hydrated - Confirms the column projection is working as intended
- Uses
Benchmark (event-loop blocking)
Measured event-loop stall time for both base (sync) and PR (async) versions:
| Version | Median Stall | Max Stall |
|---|---|---|
| Base (sync, main) | 2.03-3.11 ms | 3.60-6.18 ms |
| PR (async) | 3.47-3.54 ms | 3.94-4.37 ms |
The async version shows a small fixed increase in median stall (~0.4-1.5 ms), which is within the expected range described in the async endpoints skill: "Expect a small fixed increase at every size: async statement execution and result handling now run on the loop instead of in a worker thread, about 1 ms per request."
The key benefit is that the async version yields the event loop during database I/O, allowing other requests to be processed concurrently. The sync version runs on a threadpool worker, which holds the GIL and doesn't actually block the event loop, but it also doesn't scale as well under concurrent load.
Conclusion
The migration is correct and follows the established patterns for async endpoint conversions in Airflow. The column projection avoids the overhead of full entity hydration, and the benchmark confirms acceptable event-loop blocking behavior.
Recommendation: Approve and merge.
Migrate the Execution API
GET /execution/dags/{dag_id}(get_dag) endpoint from synchronousSessionDeptoAsyncSessionDepso database reads yield the event loop without occupying a threadpool worker.Instead of calling
session.get(DagModel, dag_id)(which selects all 35DagModelcolumns and lazily queriesdag_model.tags), project only the 7DagModelcolumns required byDagResponseandDagTag.name, avoiding fullDagModelandDagTagORM entity hydration and lazy-loading on the async session.related: #67799
Was generative AI tooling used to co-author this PR?
Generated-by: Google Antigravity following the guidelines
#77206.significant.rst, in airflow-core/newsfragments.