bryancall opened a new pull request, #14034:
URL: https://github.com/apache/trafficserver/pull/14034
### What
With the OpenSSL QUIC backend, `QUICNetVConnection::stream_write_capacity()`
now offers a stream as much room as two limits allow, whichever is smaller:
- the per-stream limit `proxy.config.quic.max_stream_send_buffer` (default 1
MB), minus what OpenSSL already holds for that stream;
- the per-connection limit `proxy.config.quic.max_connection_send_buffer`
(default 4 MB), minus what OpenSSL holds for all of the connection's streams.
Before this change it offered only the free space in OpenSSL's current
stream send buffer, capped at 16 KB.
Each stream that has data to send may hold at most an equal share of the
connection limit, but not below 16 KB, as well as the per-stream limit. Once
the connection limit binds, OpenSSL frees room a little at a time as the peer
acknowledges data, and each pass visits the streams in the same order, so
without the share the first stream would take all of that room while the others
waited. With more streams than the connection limit divided by 16 KB, the
shares add up to more than the limit, so the limit alone decides and freed room
again goes to the streams in pass order. That cannot happen at the defaults (it
would take 257 streams with data on one connection), only with a small limit or
very many streams.
Each pass over a connection's streams also splits the sending among the
streams that have data (`QUICStream::compute_fair_send_budget`), so one large
response cannot hold up the others.
A stream that HTTP/3 has finished with keeps its SSL object, marked as
draining, for as long as OpenSSL still holds data for it. That data counts
toward the connection limit. A draining stream gets one call per pass, a read
of its send buffer use, and is freed once it reads 0 (all data acknowledged, or
the sending side reset).
When a stream's sending side is reset, as after the peer sends STOP_SENDING,
or its connection closes, ATS stops writing to it. A reset already visible at
the start of a pass is skipped without a `stream_write_capacity()` call; one
that lands partway through a pass, while a write processes incoming packets,
makes `stream_write_capacity()` return -1. Either way ATS makes no further
write calls to that stream, it no longer counts among the streams with data, so
it takes nothing from the others' shares, and a debug line notes the reset
once. The function also returns -1, with a debug line, when OpenSSL's buffer
getters fail.
### Why
OpenSSL creates each QUIC stream's send buffer at 8 KB. It enlarges the
buffer only when a single write offers more data than the buffer has free; the
growth is bounded by the stream's flow control window and by OpenSSL's internal
6 MB ceiling. ATS asked `SSL_get_stream_write_buf_avail()` how much room there
was and never offered more, so the buffer never grew. The buffer also keeps
sent data until the peer acknowledges it, so a stream could never have more
than 8 KB in flight.
Same setup, before and after: one connection, one request at a time, a 1 MB
response. Master manages 7.4 Mbps from the origin and 6.3 Mbps on a cache hit.
With a 1 MB per-stream limit it manages 208 and 189 Mbps.
### The two new records
Both are resource bounds that trade throughput against memory. Both apply
only to the OpenSSL QUIC backend and need a restart.
- `proxy.config.quic.max_stream_send_buffer`, 1 MB by default. A stream can
have at most this much unacknowledged data in flight. 1 MB is enough for about
840 Mbps per stream at a 10 ms round trip, and stays well under OpenSSL's 6 MB
ceiling. A send buffer OpenSSL has grown does not shrink until the stream ends,
so a larger value costs memory for the life of each busy stream.
- `proxy.config.quic.max_connection_send_buffer`, 4 MB by default. This caps
the total OpenSSL holds for one connection. Without it, send-buffer memory
would grow with the number of concurrent streams on the connection. Each stream
with data may hold at most an equal share of it, but not below 16 KB.
Both count all stream data, control and QPACK streams included.
A transaction's count of bytes sent includes data handed to OpenSSL but not
yet delivered to the peer, up to the per-stream limit.
### Debug line and tests
After each stream write, a `v_quic_net` debug line logs what OpenSSL holds
for the stream, the buffer size and the connection total:
stream 0: OpenSSL holds 175555 bytes to send or to be acknowledged in a
190778-byte buffer, 175555 for the connection
New Uranium tests, `tests/uranium_tests/h3/test_h3_stream_send_buffer.py`;
each skips unless ATS is built with the OpenSSL QUIC backend:
- **Growth.** A 1 MB GET. Asserts that a stream's buffer grows past the size
first logged for it, and that no stream holds more than the per-stream limit
plus 16 KB.
- **Small flow control windows.** An aioquic client with `max_stream_data`
set to 16384, then 10000. Each fetches 1 MB and checks it byte for byte, then
makes a second request on the same connection. This covers a FIN that has to
wait for a partially accepted write.
- **Stream limit.** A 256 KB stream limit, a 1 MB response, and a client
that acknowledges nothing, with a stream window and a connection limit both
larger than the response. Asserts that OpenSSL holds at most the stream limit
plus 16 KB for the stream, and at least the limit minus 16 KB, so the limit was
reached.
- **Connection limit.** Eight concurrent 1 MB GETs with a 64 KB connection
window and a 2 MB connection limit. Asserts that OpenSSL never holds more than
the limit plus 16 KB for the connection.
- **The connection limit is shared.** A 256 KB connection limit and a client
that grows its connection window by 32 KB every 20 ms, so the limit binds and
room frees only as credit is granted and used. Four 1 MB GETs, then a 100-byte
GET once the large responses have 512 KB between them. Asserts that the small
response completes before any large one, and that when the first large response
completes, each of the others has at least half of its body.
- **Finished streams count toward the connection limit.** The client
requests eight 512 KB responses one after another on one connection and
acknowledges none of the response data, so OpenSSL keeps everything ATS hands
it. Each response fits under the stream limit, so ATS finishes it while OpenSSL
still holds all of it. The test sums what OpenSSL reports holding for each
stream and asserts that the sum stays within the 2 MB connection limit plus 16
KB. It also asserts that at least three streams held more than the 524288-byte
body (the rest is HTTP/3 framing), which is all that fit, so a pass means
finished streams were counted. Four streams sharing the limit at once hold
exactly 524288 each without any finishing, which the strict check rules out.
- **STOP_SENDING.** The client stops one stream partway through a 1 MB
response, then makes a second 1 MB GET. Asserts that ATS notes the reset
exactly once, that at most one write to the stream fails (one may already be
under way when the reset arrives), and that the second request completes.
- **Cancelled streams leave the share alone.** A 256 KB connection limit.
The client cancels three 1 MB responses with STOP_SENDING, then requests a
fourth and acknowledges nothing more. Asserts that OpenSSL comes to hold the
whole limit, within 16 KB, for the live stream, which it would not if the
cancelled streams still counted among those with data.
New unit test in `test_QUICStream.cc`: `send_data` sends the FIN with the
last byte after the last block is only partly accepted, whether the earlier
write took some of the block or none of it.
The large-response replay checks that the proxy's response body contains its
last two tokens.
Red and green, measured:
| test | without the change | with the change |
|---|---|---|
| growth | fails 3 of 3: no stream grew past its first logged size (8192) in
233, 241 and 236 writes | passes 3 of 3; first size 8192, largest 190778 |
| connection limit (capacity ignores the connection) | fails: OpenSSL held
5097329 bytes for the connection, limit 2097152 | passes 3 of 3; largest
connection total 2097152 |
| stream limit (capacity ignores the stream limit) | fails: OpenSSL held
1048803 bytes for one stream, limit 262144; growth, connection limit and the
shared and finished-streams tests all still pass | passes 3 of 3; OpenSSL holds
262144 |
| connection limit is shared (without the share) | fails: the small response
completed after three of the four large ones; when the first large one
completed, another had 0 bytes | passes 3 of 3; the large ones had 75384 to
228708 bytes when the small one completed, and the others had 913399 to 1000934
(87% to 95% of the body) when the first completed |
| finished streams count (without the draining commit) | fails: OpenSSL held
4195499 bytes across 9 streams against 2097152 (4195494 with the strict
whole-response check) | passes 3 of 3; 3 streams held more than the body each
run, OpenSSL holds 2097152 |
| STOP_SENDING (without the reset handling) | fails: ATS noted the reset 31
times for the one cancelled stream | passes 3 of 3; noted once, 0 failed writes
|
| cancelled streams leave the share (reset streams counted in the split) |
fails: OpenSSL held at most 65536 bytes for the live stream, a quarter of
262144; the other 7 tests pass | passes 3 of 3; OpenSSL holds 262144 for the
live stream |
| small windows | passes (regression guard) | passes 3 of 3 |
Each "without" column runs the new test against the code before the fix it
covers, or for the stream limit and the cancelled-streams share against a build
with that one check removed.
Under ASAN with OpenSSL 3.5, `test_net` passes 96 of 96. The h3 directory
passes 19 and skips 1 (Go older than 1.24); the qmux directory, last run at
`e16cc2deec`, skips its one test (no QMux in this build). They report no
AddressSanitizer errors. Their leak reports are the 16-byte
`Http3ProtocolEnforcer` that `Http3App` never deletes, in 11 tests, and in
`test_h3_python_client` the members of two `QUICNetVConnection` objects (CID
string, `QUICContext`, SNI buffer, stream map buckets); master's build leaks
the same sites in that test, in 8 of 8 runs.
### Measurements
Release builds with the tuned config, 32 net threads; h2load over HTTP/3
from a separate client host. 1 MB cells use 32 connections x 2 streams and
report body Gbps; 1 KB cells use 64 connections x 8 streams and report
requests/s. Each run is 10 s after a 3 s warm-up; each cell runs 3 times per
round, in two rounds interleaved A, B, B, A. A = master `d10662601b`, B = this
change. Each column is that round's median of 3. Every run was valid: no
failed, errored or timed-out requests and no non-2xx responses, and no crash
logs.
| cell | A r1 | A r2 | B r1 | B r2 | B vs A | A/A spread |
|---|---|---|---|---|---|---|
| h3, origin, 1 MB (Gbps) | 0.38 | 0.32 | 1.98 | 1.99 | 5.2x (A's runs are
0.32 or 0.38; median of all six 0.38) | runs 0.32 to 0.38 |
| h3, cache hit, 1 MB (Gbps) | 0.27 | 0.27 | 2.43 | 2.47 | 9.1x | runs all
0.27 |
| h3, origin, 1 KB (req/s) | 6,186 | 6,175 | 6,201 | 6,145 | -0.1% | 0.2% |
| h3, cache hit, 1 KB (req/s) | 8,511 | 8,599 | 8,601 | 8,439 | -0.4% | 1.0%
|
The 1 KB cells are unchanged: both differences are inside master's spread
between rounds. An earlier run of the same cells on the change before the
fair-share and reset commits gave the same picture (1 MB 1.98 to 1.99 and 2.42
to 2.43 Gbps; 1 KB -0.6% and +0.3%).
CPU per GB, 1 MB cache hits, from the proxy host's CPU use (32 cores): A
12.3 CPU-seconds per GB (1.3% at 0.27 Gbps), B 3.8 (3.6% at 2.45 Gbps). For B:
0.036 x 32 = 1.15 cores, 2.45 / 8 = 0.31 GB/s, 1.15 / 0.31 = 3.8.
One connection x 16 streams, 1 MB cache hits (h2load -t1 -c1 -m16, 10 s): A
16.0, 12.8 and 12.8 req/s; B 297.4, 328.0 and 302.1 req/s, about 23x.
On the old base `8bbb06314`, the same cell with a 1 GB connection limit ran
at 272.0, 272.0 and 270.7 req/s, the same as with 4 MB (270.9, 270.8, 272.0),
so the 4 MB limit costs nothing measurable here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]