fix(server): batch stream-chunk dispatch#1367
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the OpenAI API server streaming path to batch-dispatch stream chunks per engine “step”, reducing call_soon_threadsafe scheduling overhead on the API event loop at high batch sizes.
Changes:
- Buffer per-sequence stream chunks in the OpenAI server callback and flush them in a single batched dispatch (
flush_stream_batch). - Update
EngineCoreMgrSTREAM handling to run per-sequence callbacks first, then flush the batched stream chunks once per step. - Add a lazy-resolved flush hook in
EngineCoreMgrto avoid an import cycle.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
atom/model_engine/engine_core_mgr.py |
Runs callbacks for STREAM outputs and then triggers a single batched flush per step; adds lazy flush resolver. |
atom/entrypoints/openai/api_server.py |
Implements thread-local buffering for stream chunks and a flush_stream_batch() function to batch-dispatch them onto the API loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+425
to
+431
| try: | ||
| from atom.entrypoints.openai.api_server import flush_stream_batch | ||
|
|
||
| fn = self._flush_stream_batch_fn = flush_stream_batch | ||
| except Exception: | ||
| self._flush_stream_batch_fn = lambda: None # resolve to no-op | ||
| return |
valarLip
approved these changes
Jun 26, 2026
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.
Motivation
In DP high conc, such as 1024, when part of requet finished inference, schedule can not get new request immediately, It will wait for approximately 10 seconds.
Buffer chunks per-seq (decode only) and flush a whole decode step with one scheduled call. TTFT Mean -41% / Median -69%, throughput unchanged
before
after
Technical Details
Test Plan
Test Result
Submission Checklist