Skip to content

perf(server): tune HTTP/2 settings, single-chunk response framing, and disk decode - #231

Merged
shikhar merged 3 commits into
mainfrom
t3/tune-hyper-frame-size
Nov 23, 2026
Merged

shikhar merged 3 commits into
mainfrom
t3/tune-hyper-frame-size

Conversation

@shikhar

@shikhar shikhar commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Server-side HTTP/2, single-entry hot-path, and cache-decode performance improvements:

  1. HTTP/2 server concurrency (src/bin/server.rs):

    • Raise max_concurrent_streams from hyper's default 200 to 1024 so clients sharing a single HTTP/2 connection per instance can multiplex bursts beyond 200 in-flight fetches.
    • Note: SETTINGS_MAX_FRAME_SIZE is receiver-advertised in HTTP/2, so cachey's outbound DATA frame size is governed by the client.
  2. Single-entry fast path & trailer-free single-chunk framing (src/service/mod.rs, src/service/routes.rs):

    • Introduce FetchPlan (SingleEntryFetch / MultiPageFetch) shared by both routes::fetch and CacheyService::get so single-entry fetches bypass Box::pin(stream), Arc<EntryGetExecutor>, buffered(2) (FuturesOrdered), and StreamBody/async_stream entirely, returning axum::body::Body::from(chunk.data).
    • Over HTTP/2 this lets hyper set END_STREAM directly on the final DATA frame instead of emitting an extra empty HEADERS(END_STREAM) trailers frame (clients now observe no trailing header block on single-chunk and early-EOF responses instead of an empty one).
    • Multi-page responses still stream via MultiPageFetch::stream and emit per-page c0-status trailers.
  3. Zero-fill elimination in CacheValue::decode (src/cache.rs):

    • Replace BytesMut::zeroed(data_len) + reader.read_exact with Vec::with_capacity(data_len) + reader.take(data_len as u64).read_to_end(&mut buf) + exact-length UnexpectedEof check + Bytes::from(buf), avoiding zero-filling up to 16 MiB before immediately overwriting it on disk reads.

Benchmark results (release loopback, axum-server 0.9.2 / rustls 0.23.46 / hyper 1.12.0 / h2 0.4.20 / reqwest 0.13.5)

  • Small 4 KiB reads (c=8, 4000 reqs, TLS+H2):
    • StreamBody + empty trailers: 38.3–39.7k RPS (p50 198–206 µs, p99 317–329 µs)
    • Single-chunk Body::from(Bytes): 44.5–45.3k RPS (+14–16% RPS, p50 174–177 µs, p99 276–291 µs)
  • CacheValue::decode (16 MiB page):
    • BytesMut::zeroed + read_exact: 872 µs
    • Vec::with_capacity + take().read_to_end: 557 µs (1.57× faster, zero reallocation)

Verification

  • cargo +nightly fmt
  • cargo clippy --locked --workspace --all-features --all-targets -- -D warnings --allow deprecated
  • cargo nextest run --locked --all-features --lib --bins + --tests (222 passed, including HTTP/2 single-chunk, multi-page, and early-EOF framing tests and UnexpectedEof decode test)
  • Note: cargo deny check currently flags pre-existing RUSTSEC-2026-0592 on url 2.5.8 in Cargo.lock (untouched by this PR).

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

This PR speeds up single-entry responses and disk reads.

  • Single-entry reads return as one plain response body.
  • HTTP/2 connections can carry 1024 concurrent request streams.
  • Disk reads fill cache payloads without zeroing a full buffer first.
  • Memory-only cache builds skip foyer's separate runtime.

No new actionable issues or repository-rule violations were found. Checks were source-based; no tests were run during this review.

Reviews (2) · Last reviewed commit: "perf(server): bypass stream machinery fo..." · Reviewed by Greptile

@shikhar
shikhar merged commit 71a9e4d into main Nov 23, 2026
6 of 7 checks passed
@shikhar
shikhar deleted the t3/tune-hyper-frame-size branch November 23, 2026 08:06
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
shikhar pushed a commit that referenced this pull request Nov 23, 2026
## 🤖 New release

* `cachey`: 0.13.6 -> 0.13.7

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.13.7](0.13.6...0.13.7)
- 2026-11-23

### Other

- *(deps)* upgrade dependencies and fix RUSTSEC-2026-0592
([#233](#233))
- *(server)* tune HTTP/2 settings, single-chunk response framing, and
disk decode ([#231](#231))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant