You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTTP/1 writes a response through two channels, which blocks a non-blocking append #179
Found while trying to give HttpResponse a non-blocking append (#177), and it outlives that attempt.
Every byte of an HTTP/1 response goes through http_connection_send → http_connection_send_raw, which submits a uv_write and awaits its completion (src/core/http_connection.c:1374-1389). So a streamed chunk always parks the handler coroutine, whether or not the socket had room. A non-blocking offer is impossible on this path by construction.
The connection also owns a second writer, http_connection_send_batched, which keeps one write in flight and coalesces the rest into out_pending_buf, submitted from the completion callback (:1588-1606). It never suspends. WebSocket's trySend() uses it, and http_connection_outbound_over_highwater() measures its tail.
Using the second writer for streamed chunks is what does not work today, and the reason is ordering. Headers (h1_emit_headers_once), a blocking send(), and the terminal 0\r\n\r\n from mark_ended all take the raw path. A chunk body queued in out_pending_buf therefore sits behind an in-flight write while the next raw send goes out immediately and reaches the peer first. Chunked framing does not survive that: the client reads the terminal chunk, then parses the stranded body as a chunk-size line, and on a keep-alive connection the desync poisons every pipelined response behind it. TLS has its own version — tls_fsm_send_plaintext_atomic writes straight to SSL while headers went through the ring — plus a high-water mark that reads out_pending_len, a buffer TLS connections never fill.
What is needed
One serialized outbound path per connection for HTTP/1 response bytes — headers, chunks and the terminal chunk through the same writer — with backpressure read from that writer's own depth. A blocking producer then suspends on the drain event rather than on a write completion, and a non-blocking one gets a refusal that means something. That also removes a park from the streaming hot path, where every chunk currently costs one await.
Measured, on a release PHP built for the run. Numbers and method in dev/BENCHMARKS.md, entry 2026-08-20.
strace -e trace=write,epoll_pwait on one request of four 16 KiB chunks: three write(2) and three zero-timeout epoll_pwait per chunk, whatever the chunk
size, plus one write for the headers and one for the terminator. The loop turn
after each write is the coroutine suspending — async_io_req_await returns early
only on req->completed, and libuv's inline-write fast path does not fire for
back-to-back writes on one stream.
Body held at 64 KiB, only the chunk count moved. wrk -t1 -c4 -d6s, three runs
per cell, median. The second build differs by one hunk: the three pieces are
copied into one buffer and sent as a single awaited write.
chunks
chunk
three writes
one write
gain
1
64 KiB
15746
17207
+9.3%
4
16 KiB
8320
11876
+42.7%
16
4 KiB
2938
5209
+77.3%
64
1 KiB
893
1650
+84.8%
Per-chunk cost is flat in the chunk size and halves: ~18.5 µs to ~8.8 µs. The two
extra syscalls and two extra loop turns are worth about 10 µs per chunk.
What it decides
The whole measured win is reachable by coalescing the frame at the call site. That
needs no queue on the connection, no second writer to order against and no
per-response structure — the three things both designs in dev/PLAN.md foundered
on. So this issue's own proposal is not what the number supports; the coalesced
frame is, and it should land as its own change.
What remains genuinely open here is the other half: tryWrite() cannot refuse on
HTTP/1, and awaitWritable() has nothing to wait for. That has to be argued on its
own, because nothing in this measurement touches it.
One obstacle for the coalesced frame: the prototype copies the chunk because the
ABI has no awaitable vectored write. io_pipe_writev_cb
(php-src/ext/async/libuv_reactor.c:4947) sends no NOTIFY and frees the request
itself, so ZEND_ASYNC_IO_WRITEV is fire-and-forget by construction. Dropping the
copy means adding that op to ext/async; keeping it still wins by the numbers above.
Measured, on e246dcf with the release PHP at ABI 0.25 and strace -f -c around tests/perf/servers/server_stream.php. Two runs per configuration differing only in how
many chunks a response carries, so the difference divides out startup and the request
itself. Recorded in dev/BENCHMARKS.md (server#191).
transport
chunk
chunks measured
submits
waits
per chunk
plaintext
4 KiB
960
960 writev
1009
1.00 submit, 1.05 waits
plaintext
64 KiB
480
480 writev
510
1.00 submit, 1.06 waits
TLS
4 KiB
480
249 write
69
0.52 writes, 0.14 waits
This issue was argued from three submits and up to three suspensions per chunk. On
plaintext both are one, flat in the chunk size — #184 made the frame a single vectored
write and #186 made it a single awaited one. On TLS the BIO ring already batches: two
chunks share a socket write and most chunks never park.
What is left to win is the one park per chunk on plaintext, and a queue can only take it
by making the write fire-and-forget. That is the same fire-and-forget the body-contract
work removed from this path: with it, isWritable() cannot report a failed write and tryWrite() has no depth to refuse from. Recommend closing this in favour of the
documented HTTP/1 exception, unless the park itself turns out to cost something a
throughput measurement can show.
Activity
docs(bench): the three writes per HTTP/1 chunk cost 10 us of the 18.5 (…
EdmondDantes commentedon Aug 20, 2026
Measured, on a release PHP built for the run. Numbers and method in
dev/BENCHMARKS.md, entry 2026-08-20.strace -e trace=write,epoll_pwaiton one request of four 16 KiB chunks: threewrite(2)and three zero-timeoutepoll_pwaitper chunk, whatever the chunksize, plus one write for the headers and one for the terminator. The loop turn
after each write is the coroutine suspending —
async_io_req_awaitreturns earlyonly on
req->completed, and libuv's inline-write fast path does not fire forback-to-back writes on one stream.
Body held at 64 KiB, only the chunk count moved.
wrk -t1 -c4 -d6s, three runsper cell, median. The second build differs by one hunk: the three pieces are
copied into one buffer and sent as a single awaited write.
Per-chunk cost is flat in the chunk size and halves: ~18.5 µs to ~8.8 µs. The two
extra syscalls and two extra loop turns are worth about 10 µs per chunk.
What it decides
The whole measured win is reachable by coalescing the frame at the call site. That
needs no queue on the connection, no second writer to order against and no
per-response structure — the three things both designs in
dev/PLAN.mdfounderedon. So this issue's own proposal is not what the number supports; the coalesced
frame is, and it should land as its own change.
What remains genuinely open here is the other half:
tryWrite()cannot refuse onHTTP/1, and
awaitWritable()has nothing to wait for. That has to be argued on itsown, because nothing in this measurement touches it.
One obstacle for the coalesced frame: the prototype copies the chunk because the
ABI has no awaitable vectored write.
io_pipe_writev_cb(
php-src/ext/async/libuv_reactor.c:4947) sends no NOTIFY and frees the requestitself, so
ZEND_ASYNC_IO_WRITEVis fire-and-forget by construction. Dropping thecopy means adding that op to ext/async; keeping it still wins by the numbers above.
fix(http1): bound the coalesced frame by the TLS ring, not by the chu…
perf(http1): send a streamed chunk as one write below 32 KiB (#179)
docs(bench): where the chunk copy stops paying, and the noise floor i…
fix(http1): bound the coalesced frame by the TLS ring, not by the chu…
perf(http1): the header block rides with the first streamed chunk (#179)
docs(bench): the header block in the first frame is +28.5% on a one-c…
test: cover the backpressure trio behind compression and the pool (#177…
Merge pull request #184 from true-async/179-coalesce-h1-chunk
http1: tighten the comments and drop a wrapper around one if (#179)
fix(http1): the frame's CRLF is a fresh string, not a runtime-interne…
fix(http1): gate on the API version, and close the two header sends t…
test(http1): the cancel test now reads the frames and the tail (#179)
fix(http1): dispose must not seal a frame a cancellation cut in half (#…
Merge pull request #186 from true-async/179-awaited-frame-slots
docs(bench): the same chunk over TLS costs half a write and a seventh…
docs(bench): the same chunk over TLS costs half a write and a seventh…
EdmondDantes commentedon Aug 21, 2026
Measured, on
e246dcfwith the release PHP at ABI 0.25 andstrace -f -caroundtests/perf/servers/server_stream.php. Two runs per configuration differing only in howmany chunks a response carries, so the difference divides out startup and the request
itself. Recorded in
dev/BENCHMARKS.md(server#191).This issue was argued from three submits and up to three suspensions per chunk. On
plaintext both are one, flat in the chunk size — #184 made the frame a single vectored
write and #186 made it a single awaited one. On TLS the BIO ring already batches: two
chunks share a socket write and most chunks never park.
What is left to win is the one park per chunk on plaintext, and a queue can only take it
by making the write fire-and-forget. That is the same fire-and-forget the body-contract
work removed from this path: with it,
isWritable()cannot report a failed write andtryWrite()has no depth to refuse from. Recommend closing this in favour of thedocumented HTTP/1 exception, unless the park itself turns out to cost something a
throughput measurement can show.
docs(http1): say what the awaited writev size check guards (#179)
docs(http1): say what the awaited writev size check guards (#179)
Merge pull request #191 from true-async/h1-queue-measurement
fix(http1): refuse a non-blocking chunk from the outbound depth (#179)
Merge pull request #214 from true-async/179-serialized-h1-outbound
Merge pull request #218 from true-async/plan-close-trywrite-step