Skip to content

[serve][llm] Add a byte-relay OpenAI ingress with no per-token Python objects - #66603

Closed
johntaylor-cell wants to merge 2 commits into
ray-project:masterfrom
johntaylor-cell:llm-byte-relay
Closed

johntaylor-cell wants to merge 2 commits into
ray-project:masterfrom
johntaylor-cell:llm-byte-relay

Conversation

@johntaylor-cell

@johntaylor-cell johntaylor-cell commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

OpenAiIngress relays every streamed token through a DeploymentHandle as its own object on one event loop, which caps it near 13k tokens/s on a 32 vCPU node. This PR adds ByteRelay, an ingress that stays in the response path but reads each LLMServer replica's own HTTP stream and writes the bytes straight to the client socket, with no per-token Python objects.

build_byte_relay_apps(llm_config) returns the backend app (LLMServer without LLMRouter) and the relay app; run both with serve.run. It needs direct ingress (RAY_SERVE_THROUGHPUT_OPTIMIZED=1), and relay_replicas scales the relay tier.

One m5.8xlarge, CPU mock engine at 2.3 ms per token, n=2 except OpenAiIngress:

Path req/s at concurrency 256 Mean TTFT Mean TPOT tokens/s at 640 streams
OpenAiIngress 27.4 971 ms 16.3 ms capped near 14k
Direct streaming 212.3 34 ms 2.31 ms 248k
ByteRelay 215.8 44 ms 2.26 ms 238k

Additional information

  • Two new files, no changes to existing code.
  • Follow-up: a Serve API that hands the client socket to the app, replacing the relay's walk through the send wrappers.

…objects

OpenAiIngress relays every token as its own object on one event loop, which caps it near
13k tokens/s on a 32 vCPU node. ByteRelay stays in the response path but reads each LLMServer
replica's own HTTP stream and writes the chunked bytes straight to the client socket.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
@johntaylor-cell
johntaylor-cell requested a review from a team as a code owner September 30, 2026 14:10
@johntaylor-cell
johntaylor-cell marked this pull request as draft September 30, 2026 14:10
@johntaylor-cell johntaylor-cell self-assigned this Sep 30, 2026
@johntaylor-cell johntaylor-cell added serve Ray Serve Related Issue llm go add ONLY when ready to merge, run all tests labels Sep 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces ByteRelay, a high-performance OpenAI ingress that streams chunk-framed HTTP data directly from LLMServer replicas to client sockets to avoid per-token Python object overhead. Feedback focuses on addressing a latency and correctness issue where unconditionally holding back the last 5 bytes of every read delays chunk trailing bytes, suggesting instead to only buffer bytes matching a prefix of the terminator. Additionally, it is recommended to increase the backpressure polling interval from 1ms to 10ms to significantly reduce CPU overhead under backpressure.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 48ab291. Configure here.

…p expect

Holding back the last 5 bytes of every read delayed each token until the next one arrived;
now only a suffix that could start the final chunk waits. The relay no longer forwards
Expect or other hop-by-hop headers, skips interim 1xx responses, and polls a slow client's
buffer every 10 ms instead of every 1 ms.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: john.taylor <[email protected]>
@johntaylor-cell johntaylor-cell changed the title [serve][llm] Add a byte-relay OpenAI ingress with no per-token Python objecst [serve][llm] Add a byte-relay OpenAI ingress with no per-token Python objects Oct 6, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests llm serve Ray Serve Related Issue stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant