Skip to content

[serve] Increase HAProxy ingress buffer and lower maxconn - #66360

Merged
eicherseiji merged 5 commits into
ray-project:masterfrom
eicherseiji:seiji/increase-haproxy-router-buffer-16m
Sep 22, 2026
Merged

eicherseiji merged 5 commits into
ray-project:masterfrom
eicherseiji:seiji/increase-haproxy-router-buffer-16m

Conversation

@eicherseiji

@eicherseiji eicherseiji commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Why

The current 256 KiB cap truncates the router copy of large LLM requests, causing body-aware routing to lose information. Several recent routing changes depend on this body:

  • #64224, #64328, and #65095 use it for KV-aware routing.
  • #65680 uses it for LoRA model selection.
  • #66258 and #66315 use it for deployment-aware, multi-model direct streaming.
  • #63183 introduced the body-forwarding gate shared by these paths.

This PR raises the default buffer to 8 MiB and lowers the default maxconn to 4,096. The sizing and behavior were verified with a real HAProxy 2.8.25 test and against the bundled HAProxy source code. Both settings retain their existing environment-variable overrides.

Consideration Result
Request size A one-million-token English request is commonly estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves 2.28 MiB (~40%) headroom.
Latency Requests below 256 KiB do not wait longer. Requests from 256 KiB to 8 MiB now wait for the complete body before routing.
Memory Buffers are allocated dynamically. A live stream can use roughly 16 MiB across request and response buffers. Lowering maxconn from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB to 64 GiB.

Changes

  • Raise RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE from 256 KiB to 8 MiB.
  • Lower RAY_SERVE_HAPROXY_MAXCONN from 20,000 to 4,096.
  • Test a 6,000,014-byte, million-token-sized request end to end.
  • Derive rendered-config assertions from their constants so environment overrides remain testable.
  • Update the KV-aware routing guide.

Tests

  • Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly passed.
  • HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using bundled HAProxy 2.8.25.

This does not duplicate the related PRs: they introduce or consume body-aware routing, while this PR increases the shared buffer default and tests a million-token-sized body.

AI assistance was used to implement and validate this change; the submitter reviewed every changed line.

@eicherseiji eicherseiji self-assigned this Sep 22, 2026
@eicherseiji eicherseiji added the go add ONLY when ready to merge, run all tests label Sep 22, 2026
@eicherseiji eicherseiji changed the title [serve] Increase HAProxy ingress router buffer to 16 MiB [serve] Increase HAProxy ingress router buffer to 8 MiB Sep 22, 2026
@eicherseiji
eicherseiji deleted the seiji/increase-haproxy-router-buffer-16m branch September 22, 2026 06:29
@eicherseiji
eicherseiji restored the seiji/increase-haproxy-router-buffer-16m branch September 22, 2026 06:31
@eicherseiji eicherseiji reopened this Sep 22, 2026
@eicherseiji
eicherseiji marked this pull request as ready for review September 22, 2026 06:50
@eicherseiji
eicherseiji requested review from a team as code owners September 22, 2026 06:50

@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 increases the default HAProxy request-buffer size (RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE) from 262 KiB to 8 MiB to support routing larger request bodies, updating the documentation and adding corresponding end-to-end tests. Feedback on these changes highlights a high risk of Out-Of-Memory (OOM) crashes under heavy load due to the large buffer size combined with high connection limits, and suggests dynamically capping connection limits or logging warnings. Additionally, it is recommended to dynamically assert the buffer size in tests using the imported constant rather than hardcoding the value.

Comment thread python/ray/serve/_private/constants.py Resolved
@ray-gardener ray-gardener Bot added serve Ray Serve Related Issue docs An issue or change related to documentation labels Sep 22, 2026
@eicherseiji eicherseiji changed the title [serve] Increase HAProxy ingress router buffer to 8 MiB [serve] Increase HAProxy ingress buffer and lower maxconn Sep 22, 2026

@jeffreywang88 jeffreywang88 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.

:shipit:

# tokenizers. Verify that a request approximating a million-token
# prompt (and well over the old 256 KiB cap) reaches both the
# router and selected replica intact.
large_body = json.dumps({"prompt": " token" * 1_000_000})

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.

million-token prompt

nice!

@eicherseiji
eicherseiji enabled auto-merge (squash) September 22, 2026 19:05
@eicherseiji
eicherseiji merged commit 0a2c436 into ray-project:master Sep 22, 2026
7 checks passed
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
…t#66360)

## Why

The current 256 KiB cap truncates the router copy of large LLM requests,
causing body-aware routing to lose information. Several recent routing
changes depend on this body:

- [ray-project#64224](ray-project#64224),
[ray-project#64328](ray-project#64328), and
[ray-project#65095](ray-project#65095) use it for
KV-aware routing.
- [ray-project#65680](ray-project#65680) uses it for
LoRA model selection.
- [ray-project#66258](ray-project#66258) and
[ray-project#66315](ray-project#66315) use it for
deployment-aware, multi-model direct streaming.
- [ray-project#63183](ray-project#63183) introduced the
body-forwarding gate shared by these paths.

This PR raises the default buffer to 8 MiB and lowers the default
`maxconn` to 4,096. The sizing and behavior were verified with a real
HAProxy 2.8.25 test and against the bundled HAProxy source code. Both
settings retain their existing environment-variable overrides.

| Consideration | Result |
|---|---|
| Request size | A one-million-token English request is commonly
estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves
2.28 MiB (~40%) headroom. |
| Latency | Requests below 256 KiB do not wait longer. Requests from 256
KiB to 8 MiB now wait for the complete body before routing. |
| Memory | Buffers are allocated dynamically. A live stream can use
roughly 16 MiB across request and response buffers. Lowering `maxconn`
from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB
to 64 GiB. |

## Changes

- Raise `RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE` from 256 KiB
to 8 MiB.
- Lower `RAY_SERVE_HAPROXY_MAXCONN` from 20,000 to 4,096.
- Test a 6,000,014-byte, million-token-sized request end to end.
- Derive rendered-config assertions from their constants so environment
overrides remain testable.
- Update the KV-aware routing guide.

## Tests

- Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly
passed.
- HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using
bundled HAProxy 2.8.25.

This does not duplicate the related PRs: they introduce or consume
body-aware routing, while this PR increases the shared buffer default
and tests a million-token-sized body.

AI assistance was used to implement and validate this change; the
submitter reviewed every changed line.

---------

Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…t#66360)

## Why

The current 256 KiB cap truncates the router copy of large LLM requests,
causing body-aware routing to lose information. Several recent routing
changes depend on this body:

- [ray-project#64224](ray-project#64224),
[ray-project#64328](ray-project#64328), and
[ray-project#65095](ray-project#65095) use it for
KV-aware routing.
- [ray-project#65680](ray-project#65680) uses it for
LoRA model selection.
- [ray-project#66258](ray-project#66258) and
[ray-project#66315](ray-project#66315) use it for
deployment-aware, multi-model direct streaming.
- [ray-project#63183](ray-project#63183) introduced the
body-forwarding gate shared by these paths.

This PR raises the default buffer to 8 MiB and lowers the default
`maxconn` to 4,096. The sizing and behavior were verified with a real
HAProxy 2.8.25 test and against the bundled HAProxy source code. Both
settings retain their existing environment-variable overrides.

| Consideration | Result |
|---|---|
| Request size | A one-million-token English request is commonly
estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves
2.28 MiB (~40%) headroom. |
| Latency | Requests below 256 KiB do not wait longer. Requests from 256
KiB to 8 MiB now wait for the complete body before routing. |
| Memory | Buffers are allocated dynamically. A live stream can use
roughly 16 MiB across request and response buffers. Lowering `maxconn`
from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB
to 64 GiB. |

## Changes

- Raise `RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE` from 256 KiB
to 8 MiB.
- Lower `RAY_SERVE_HAPROXY_MAXCONN` from 20,000 to 4,096.
- Test a 6,000,014-byte, million-token-sized request end to end.
- Derive rendered-config assertions from their constants so environment
overrides remain testable.
- Update the KV-aware routing guide.

## Tests

- Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly
passed.
- HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using
bundled HAProxy 2.8.25.

This does not duplicate the related PRs: they introduce or consume
body-aware routing, while this PR increases the shared buffer default
and tests a million-token-sized body.

AI assistance was used to implement and validate this change; the
submitter reviewed every changed line.

---------

Signed-off-by: Seiji Eicher <[email protected]>
Signed-off-by: Seiji Eicher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs An issue or change related to documentation go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants