Skip to content

Commit d33efd5

Browse files
alxtkr77Alex Toker
andauthored
[Model Monitoring] Fix event loop blocking during model endpoint creation (ML-11826) (#9186)
## Summary Fix event loop blocking during model endpoint creation by using `run_in_threadpool` to wrap synchronous DB operations. ## Changes Made - Wrap `run_function_with_new_db_session` call in `run_in_threadpool` in `_create_model_endpoint_limited` - Add `await` keyword for the async operation - Add explanatory comment ## Why This Change When deploying a serving function with many models (e.g., 5000), the synchronous DB operations for creating model endpoints would block the async event loop. This prevented the API server from handling other requests and could cause timeouts. Using `run_in_threadpool` moves the synchronous DB work to a thread pool, keeping the event loop responsive while still processing the model endpoint creation. ## Testing - Ran `test_app_flow[True-True]` system test successfully - Deployed serving function with 5000 models - completed in ~7 minutes with API remaining responsive ## Reference - Jira: ML-11826 Co-authored-by: Alex Toker <[email protected]>
1 parent 0be1248 commit d33efd5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

server/py/services/api/crud/model_monitoring/deployment.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,8 +1985,11 @@ async def _create_model_endpoint_limited(
19851985
delete_background_task: fastapi.BackgroundTasks,
19861986
):
19871987
async with semaphore:
1988-
result = framework.db.session.run_function_with_new_db_session(
1989-
func=services.api.crud.ModelEndpoints().create_model_endpoints,
1988+
# Use run_in_threadpool to avoid blocking the event loop
1989+
# while performing synchronous DB operations
1990+
result = await run_in_threadpool(
1991+
framework.db.session.run_function_with_new_db_session,
1992+
services.api.crud.ModelEndpoints().create_model_endpoints,
19901993
model_endpoints_instructions=model_endpoints_instructions,
19911994
project=project,
19921995
function_name=function_name,

0 commit comments

Comments
 (0)