]> git.kaiwu.me - nginx.git/commitdiff
QUIC: optimized sending stream response.
authorRoman Arutyunyan <arut@nginx.com>
Mon, 3 Apr 2023 12:17:12 +0000 (16:17 +0400)
committerRoman Arutyunyan <arut@nginx.com>
Mon, 3 Apr 2023 12:17:12 +0000 (16:17 +0400)
When a stream is created by client, it's often the case that nginx will send
immediate response on that stream.  An example is HTTP/3 request stream, which
in most cases quickly replies with at least HTTP headers.

QUIC stream init handlers are called from a posted event.  Output QUIC
frames are also sent to client from a posted event, called the push event.
If the push event is posted before the stream init event, then output produced
by stream may trigger sending an extra UDP datagram.  To address this, push
event is now re-posted when a new stream init event is posted.

An example is handling 0-RTT packets.  Client typically sends an init packet
coalesced with a 0-RTT packet.  Previously, nginx replied with a padded CRYPTO
datagram, followed by a 1-RTT stream reply datagram.  Now CRYPTO and STREAM
packets are coalesced in one reply datagram, which saves bandwidth.

Other examples include coalescing 1-RTT first stream response, and
MAX_STREAMS/STREAM sent in response to ACK/STREAM.

src/event/quic/ngx_event_quic_streams.c

index 6f0a752a7240bf38b415272a502644c9c7d03232..3b72f8339c0a58c535cb17e6c98fc836fcefcc5b 100644 (file)
@@ -472,6 +472,17 @@ ngx_quic_get_stream(ngx_connection_t *c, uint64_t id)
 
         if (qc->streams.initialized) {
             ngx_post_event(rev, &ngx_posted_events);
+
+            if (qc->push.posted) {
+                /*
+                 * The posted stream can produce output immediately.
+                 * By postponing the push event, we coalesce the stream
+                 * output with queued frames in one UDP datagram.
+                 */
+
+                ngx_delete_posted_event(&qc->push);
+                ngx_post_event(&qc->push, &ngx_posted_events);
+            }
         }
     }