Skip to content

perf: use httptools for HTTP parsing - #2869

Open
ananthsub wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/uvicorn-httptools
Open

perf: use httptools for HTTP parsing#2869
ananthsub wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/uvicorn-httptools

Conversation

@ananthsub

@ananthsub ananthsub commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Gym depends on plain uvicorn, so httptools is not guaranteed to be installed and Uvicorn can silently fall back to its pure-Python h11 parser.

This change adds httptools as a dependency and explicitly selects it in the Uvicorn configuration. Explicit selection also turns a missing or incompatible wheel into a startup error instead of silently changing the server's parser.

Performance methodology

For testing, added a synthetic benchmark that used a deterministic SimpleResponsesAPIModel which returns cached, training-shaped dictionaries. This isolates Gym's dispatch, middleware, serialization, and HTTP serving costs from model generation.

This was tested with #2867

The matrix covered:

  • 32 output tokens (4.9 KB response) at 1,024, 4,096, and 8,192 concurrent requests
  • 1,024 output tokens (22.6 KB response) at 1,024 and 4,096 concurrent requests
  • 65,536 output tokens (1.40 MB response) at 1,024 concurrent requests

The httptools-only variant improved median throughput by up to 4.2%. The result was neutral at 8,192 concurrency, where server saturation and scheduling variance dominated parser cost.

Screenshot 2026-08-28 at 5 11 33 PM Screenshot 2026-08-28 at 5 11 42 PM

Test plan

  • uv run pytest tests/unit_tests/test_server_utils.py -q
  • uv run pre-commit run --files nemo_gym/server_utils.py pyproject.toml uv.lock

Gym depends on plain uvicorn rather than uvicorn[standard], so httptools was
never installed and every server silently fell back to uvicorn's pure-Python
h11 protocol implementation for HTTP parsing.

Add httptools (C bindings to the llhttp parser) as a dependency and name it
explicitly in the uvicorn config: uvicorn's "auto" selection only picks
httptools when the wheel is importable and falls back to h11 silently, so an
explicit http="httptools" makes a missing wheel fail loudly at startup
instead of silently degrading.

Measured on a SimpleResponsesAPIModel serving training-shaped bodies through
the production middleware stack: +1-4% alone (response serialization dominates
the server today), rising to +5-11% at high request rates once the orjson
dispatch-serialization change lands. Wheels cover manylinux/musllinux aarch64
and x86_64 for cp310-cp314. No behavior change for well-formed traffic; llhttp
is stricter than h11 on malformed requests.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub
ananthsub requested a review from a team as a code owner August 29, 2026 01:00
Use short sentences to explain why Gym explicitly selects httptools and how startup behaves when the dependency is unavailable.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
@ananthsub ananthsub changed the title perf(server): use httptools for HTTP parsing perf: use httptools for HTTP parsing Aug 29, 2026
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.

2 participants