Skip to content

Conversation

@alxtkr77
Copy link
Member

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

…tion (ML-11826)

Use run_in_threadpool to wrap synchronous DB operations in
_create_model_endpoint_limited to prevent blocking the async event loop
when creating model endpoints during serving function deployment.

This ensures the API server remains responsive while processing
large batches of model endpoint creation requests.
@alxtkr77 alxtkr77 merged commit d33efd5 into mlrun:development Jan 11, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants