Skip to content

XHTTP server: Raise HTTP/2 receive windows for faster uplink - #7282

Closed
pqhaz3925 wants to merge 2 commits into
XTLS:mainfrom
pqhaz3925:xhttp-h2-window
Closed

pqhaz3925 wants to merge 2 commits into
XTLS:mainfrom
pqhaz3925:xhttp-h2-window

Conversation

@pqhaz3925

@pqhaz3925 pqhaz3925 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The XHTTP h1/h2 server uses net/http's HTTP/2 defaults: 1 MiB receive window per connection and per stream. All uplink traffic on one h2 connection (stream-up, stream-one, and packet-up over XMUX) shares that window, so uplink is capped at ~1 MiB per RTT, about 160 Mbit/s at 50 ms RTT and lower on longer paths.

This sets http.Server.HTTP2 to 10 MiB per connection and per stream (about 1.6 Gbit/s per connection at 52 ms RTT). Buffers are only allocated as data arrives. It's server-only, so existing clients benefit without changes. XHTTP/3 (QUIC windows) is not affected.

Test

VLESS + XHTTP + REALITY, stock 26.10.21 client (macOS) → Linux server, 52 ms RTT, iperf3 12 s through the tunnel (Mbit/s):

mode up ×1 up ×8 down ×1 down ×8
stream-one, before 76 171 156 367
stream-one, after 271 503 191 388
packet-up, before 140 341 169 421
packet-up, after 253 459 153 433

Download differences are within run-to-run noise; uplink improves 1.3–3.6×. (Measured with 64/16 MiB windows; the test link tops out around 500 Mbit/s, below what 10 MiB allows.)

  • go test ./transport/internet/splithttp passes

net/http's server defaults are 1 MiB per connection and per stream,
capping uplink at ~1 MiB per RTT (~160 Mbit/s at 52 ms). Raise to
64 MiB / 16 MiB, in line with the x/net/http2 client defaults.
@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

这样改会不会导致服务端内存占用量爆炸

另外你看看其它传输层/入站的情况

@pqhaz3925

Copy link
Copy Markdown
Contributor Author

Checked the other transports/inbounds; the XHTTP h1/h2 server is the only place left on the 1 MiB net/http default:

  • gRPC: grpc-go's BDP estimator grows the windows dynamically up to 16 MiB (both sides; client-side only disabled if the user sets initial_windows_size).
  • MASQUE over h2: own implementation, 6 MiB stream / 15 MiB conn.
  • QUIC-based (XHTTP/3, Hysteria, MASQUE h3): windows come from quicParams / quic-go defaults (Hysteria 8/20 MiB), unaffected.
  • XHTTP h2 client (downlink): bare x/net/http2.Transport → 4 MiB/stream, 1 GiB/conn.
  • WS / HTTPUpgrade / RAW / HTTP inbound: HTTP/1.1 or raw TCP, no h2 flow control.

On memory: these are upper bounds, not allocations. The server buffers only data that the client has sent and the handler hasn't read yet. In normal relaying the handler drains it right away. The bound only matters when the outbound is slower than the client.

@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

64MB 太大了,per connection and per stream 都改成 10MB 比较合适,先翻十倍

@pqhaz3925

Copy link
Copy Markdown
Contributor Author

Done: both are 10 MiB now (abd3628).

@Fangliding

Copy link
Copy Markdown
Member

但是对于直接监听的服务端这个属于可观测的特征 前置nginx的情况下这个归ngx管 而且这个只是 uplink 而已 一般 uplink 不会很大

@Fangliding Fangliding closed this Oct 29, 2026
@RPRX

RPRX commented Oct 29, 2026

Copy link
Copy Markdown
Member

仍需讨论

@RPRX RPRX reopened this Oct 29, 2026
@pqhaz3925

Copy link
Copy Markdown
Contributor Author

Thanks for reopening. On Fangliding's point about observability: the current 1 MiB window is itself a fingerprint (it's the Go net/http default, so it identifies a Go h2 server just as well), and it is only visible after the TLS/REALITY handshake, so a passive or active prober doesn't see it before authenticating. Behind nginx nothing changes, as noted.

If changing the default is still a concern, I can make it opt-in instead: xhttpSettings.serverMaxUploadWindow (or similar), default = current behaviour, so only users who need fast uplink set it. Which would you prefer?

@Fangliding

Copy link
Copy Markdown
Member

确实有人需要调整数个HTTP2字段 按照自由主义理念干脆透明传出允许随便填好了 我稍微弄一下

@Fangliding Fangliding closed this Oct 30, 2026
RPRX pushed a commit that referenced this pull request Oct 31, 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.

3 participants