Skip to content

XHTTP server: Advertise 16 KiB HTTP/2 max frame size - #7099

Closed
denissilantev64 wants to merge 1 commit into
XTLS:mainfrom
denissilantev64:xhttp-server-h2-frame-size
Closed

denissilantev64 wants to merge 1 commit into
XTLS:mainfrom
denissilantev64:xhttp-server-h2-frame-size

Conversation

@denissilantev64

Copy link
Copy Markdown

Go's HTTP/2 client (golang.org/x/net/http2) gives every stream a request body buffer of min(server's SETTINGS_MAX_FRAME_SIZE, 512 KiB) and keeps it for as long as it writes the body (frameScratchBufferLen / writeRequestBody). An XHTTP stream-one or stream-up request body lasts as long as the proxied connection. Go's server advertises 1 MiB, so on the client every open XHTTP stream pins 512 KiB.

A client with many connections at once pays that per connection — a browser opening a heavy page, for example. On iOS the packet tunnel provider is limited to 50 MB (#4422), and this buffer alone takes the limit.

This change makes the XHTTP server advertise 16 KiB, the protocol's initial value (RFC 9113, 6.5.2). Each stream's buffer becomes 16 KiB. It only limits frames from client to server; downloads are unaffected. Clients need no update: the protocol requires them to respect SETTINGS_MAX_FRAME_SIZE, and 16 KiB is the value they use until the server's first SETTINGS arrives.

Measurements

Setup: VLESS + XHTTP stream-one + REALITY. Server on Linux with 100 ms of netem delay, stock Xray client, the same build with and without this change.

server on main this change
client heap + stacks, 8 workers of short requests (new connection each, ~60/s), peak 88–98 MB 21 MB
one download 20.8 MB/s 21.0 MB/s
one upload 6.0 MB/s 6.0 MB/s

The same buffer was the largest single holder on an Android client (hev-socks5-tunnel in front of Xray): 70–120 MB in heap profiles with 32–64 workers of short requests.

Test

Test_ListenXH_HTTP2MaxFrameSize reads the server's first SETTINGS frame. It fails on main (1048576) and passes with this change.

Not in this PR

The other large per-stream item on the client is the HTTP/2 receive window. The XHTTP h2 transport sets none, so x/net defaults apply: 4 MiB per stream and 1 GiB per connection. With slow readers, every stream can hold up to 4 MiB.

Unlike this change, lowering the window costs throughput. At 100 ms RTT one stream does about window / RTT:

window download
256 KiB 2.4 MB/s
512 KiB 4.8 MB/s
1 MiB 9.4 MB/s
default 25 MB/s

So it would have to be opt-in, much like the window settings in quicParams for HTTP/3. We can send that as a separate PR if you tell us which config shape you prefer.

@Fangliding

Fangliding commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

迟迟没有加的原因是硬编码一个额外的值可能导致特征 对于经过转发器(如CDN)的节点又很可能不受控

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