Dev-iL commented on code in PR #74540:
URL: https://github.com/apache/airflow/pull/74540#discussion_r4280775014


##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_state_store.py:
##########
@@ -138,28 +143,28 @@ def get_asset_state_store_by_name(
     return AssetStateStoreResponse(value=json.loads(value))

Review Comment:
   Converting this handler to `async def` moves `json.loads(value)` and 
`AssetStateStoreResponse` validation from FastAPI's worker thread onto the 
server event loop. With a stored 100,000-integer array (688,890 JSON bytes), 
two SQLite benchmark rounds increased median event-loop delay from 110–113 ms 
on the base to 152–155 ms here. Offloading parsing and response-model 
construction together reduced it to 112–129 ms; the remaining delay includes 
existing framework serialization. Larger stored values therefore delay other 
requests handled by the same loop. 
   
   Suggestion: move parsing and response-model construction into 
`run_in_threadpool` after the awaited backend read, and apply the same change 
to the URI handler at `asset_state_store.py:235`.



##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/asset_state_store.py:
##########
@@ -122,14 +127,14 @@ def _resolve_asset_id_by_uri(uri: str, session: 
SessionDep) -> int:
 
 
 @router.get("/by-name/value")
-def get_asset_state_store_by_name(
+async def get_asset_state_store_by_name(
     name: Annotated[str, Query(min_length=1)],
     key: Annotated[str, Query(min_length=1)],
-    session: SessionDep,
+    session: AsyncSessionDep,
 ) -> AssetStateStoreResponse:
     """Get an asset state store value by asset name."""
-    asset_id = _resolve_asset_id_by_name(name, session)
-    value = get_state_backend().get(AssetScope(asset_id=asset_id), key, 
session=session)
+    asset_id = await _resolve_asset_id_by_name(name, session)
+    value = await get_state_backend().aget(AssetScope(asset_id=asset_id), key, 
session=session)

Review Comment:
   Both converted GET routes call `MetastoreBackend._aget_asset_state_store` at 
`state/metastore.py:551`, which selects the entire 13-column 
`AssetStateStoreModel` but returns only `row.value`. 
   
   Suggestions: select `AssetStateStoreModel.value` and return the scalar 
directly, keeping the existing filters and session. The value column is 
non-null, so missing keys still return `None`. A comparative HTTP probe on 
SQLite, PostgreSQL, and MySQL preserved the returned values and missing-key 
responses while reducing selected columns from 13 to 1 and ORM loads from one 
to zero per successful GET. Apply this to both selectors through the shared 
helper.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to