Skip to content

fix: disable Nagle's algorithm on accepted gateway connections (#376) - #380

Merged
maralbahari merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:fix/376-tcp-nodelay
Sep 30, 2026
Merged

maralbahari merged 2 commits into
vllm-project:mainfrom
Zheng-Lu:fix/376-tcp-nodelay

Conversation

@Zheng-Lu

Copy link
Copy Markdown
Contributor

Summary

Fixes #376.

Streamed responses and WebSocket turns are written as several small frames. axum 0.8 leaves Nagle's algorithm on for accepted sockets. Each frame after the first therefore waited for the client to acknowledge the previous one, and clients delay that acknowledgement (about 40 ms on Linux). As a result, every streamed /v1/responses request and every WebSocket turn took about 44 ms, even when the upstream answered in under a millisecond.

  • agentic_server::app::gateway_listener(TcpListener) wraps the listener with axum's ListenerExt::tap_io. It sets TCP_NODELAY on every accepted socket.
  • If the option cannot be set, it logs a warning and keeps serving the connection.
  • server.rs now serves through it.
  • The listener lives in the library, not the binary's server.rs, so tests exercise the exact listener production uses.

Test Plan

cargo fmt -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test -p agentic-server               # 528 passed, 0 failed
uvx pre-commit run --all-files

New crates/agentic-server/tests/gateway_listener_test.rs:

  • accepted_connections_disable_nagle accepts a connection through gateway_listener and asserts that TCP_NODELAY is set on the accepted socket. This check is deterministic.
  • streamed_frames_are_not_held_for_delayed_acknowledgements:
    • serves a handler that writes five small frames a millisecond apart through gateway_listener;
    • warms one keep-alive connection past Linux's initial quick-ACK phase;
    • asserts the median of 9 streamed responses is under 25 ms.

Negative control. With set_nodelay(false), both tests fail. The timing test reports a median of 44.06 ms (all 9 samples between 43.9 and 44.2 ms), which is exactly the stall from the issue. With the fix it passed 10 of 10 repeated runs, each in about 0.4 s.

End to end. I ran the repro script from #376 against this branch's gateway binary (debug build), with #376's release-build numbers from main for comparison:

Request main (#376, release build) p50 This branch (debug build) p50
Streamed /v1/responses 44.00 ms 2.45 ms
Blocking /v1/responses 0.74 ms 1.86 ms
WebSocket turn 44.02 ms 1.77 ms

The issue also shows a release build of the same one-line change at 0.84 ms streamed and 0.59 ms per WebSocket turn.

Notes

Streamed responses and WebSocket turns are written as several small
frames. axum 0.8 leaves Nagle's algorithm on for accepted sockets, so
each frame after the first waited for the client to acknowledge the
previous one, and clients delay that acknowledgement (about 40 ms on
Linux). Every streamed /v1/responses request and every WebSocket turn
took about 44 ms even when the upstream answered in under a millisecond.

The gateway now accepts connections through app::gateway_listener, which
sets TCP_NODELAY on each accepted socket and logs a warning, but keeps
serving, if the option cannot be set.

Fixes vllm-project#376

Signed-off-by: Zheng Lu <[email protected]>
@Zheng-Lu Zheng-Lu changed the title fix: disable Nagle's algorithm on accepted gateway connections fix: disable Nagle's algorithm on accepted gateway connections (#376) Sep 25, 2026
@maralbahari
maralbahari merged commit d3391b1 into vllm-project:main Sep 30, 2026
19 checks passed
haoshan98 added a commit that referenced this pull request Sep 30, 2026
## Summary

Several user-facing docs had fallen behind `main` or contradicted each
other and the code. This PR brings them in line with what has shipped.
It changes documentation only.


**Corrected claims**
- README listed the Messages API as "🚧 Planned" while another README
section documents `/v1/messages`. It is now listed as shipped; only
stateful Messages stays planned.
- README and `docs/index.md` advertised "Background execution" and
gateway-executed file search. Neither exists yet: background mode is
#357, and `file_search` declarations parse but are dropped before
inference (`tool/normalize.rs`). Both claims are removed.
- `docs/api/index.md` quoted fixed WebSocket and executor limits (256
KiB SSE lines, 1 MiB events and response budget). These now come from
the configurable `[responses]` settings, which default to 16 MiB and 8
MiB.
- `docs/api/index.md` listed only some of the conditions that route a
Responses request through the executor. The list now also includes
non-function tools, `multi_agent.enabled`, and tool-search state,
matching `handler/http/responses.rs`.
- CHANGELOG listed Tavily under 0.8.0, but it merged on Sep 28, after
the Sep 19 release. The two Tavily entries move to `[Unreleased]`.

**Newly documented features**
- README: a multi-agent Responses section with an example and the
gateway's limits (`store: true`, HTTP/SSE only, default of 3 concurrent
subagents, no `max_tool_calls` or reasoning summaries). Also new rows in
the API table for `/v1/responses/compact`, the full Conversations
routes, `/v1/messages` with `/v1/messages/count_tokens`, and
Swagger/OpenAPI (`ENABLE_OPENAPI_DOCS`). The features list, diagram, and
tool ownership table now include MCP, the code interpreter, Claude Code,
compaction, and OpenTelemetry.
- `docs/api/index.md`: new sections for `GET
/v1/responses/{response_id}`, multi-agent, Conversations, and Messages.
- CHANGELOG `[Unreleased]` was empty. It now has entries for #345, #347,
#349, #351/#370, #354, #368, #369, #372/#373, #380, and #387.

**Roadmap**
- ROADMAP.md marks multi-agent HTTP execution as shipped, with WebSocket
injection (#300) and stateless requests (#393) still open. It adds a
status note for Messages, a code interpreter entry, and a file search
item linking #34 and #356.
- README "Roadmap at a Glance" checks off Messages and Conversations and
adds unchecked items for multi-agent, file search, and stateful
Messages.

**Smaller fixes**
- The repository layout in README and AGENTS.md now lists
`agentic-llm-d`, `agentic-cli-docs`, and `python/agentic_api/`.
- ARCHITECTURE.md's list of multi-agent rejections now includes
`max_tool_calls`, matching `executor/rehydrate.rs`.
- `mkdocs.yaml` adds the existing but unlinked `design/shell-tool.md` to
the nav.

**Not changed:** the README's "Rust 1.85+" badge is wrong (1.85 cannot
build the lockfile, see #377), but #379 already updates it to 1.88 along
with `rust-version` and a CI check, so this PR leaves it alone to avoid
a conflict.

Signed-off-by: haoshan98 <[email protected]>
@Zheng-Lu
Zheng-Lu deleted the fix/376-tcp-nodelay branch October 9, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamed responses stall ~40 ms because the gateway does not set TCP_NODELAY on accepted connections

2 participants