changeset 8508:4604e6043657 quic

QUIC: packet based bytes_in_flight accounting. A packet size is kept in one of the frames belonging to the packet.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 14 Aug 2020 16:54:13 +0300
parents 7f9938cbcd12
children bce9e9643444
files src/event/ngx_event_quic.c src/event/ngx_event_quic_transport.h
diffstat 2 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/event/ngx_event_quic.c
+++ b/src/event/ngx_event_quic.c
@@ -288,7 +288,8 @@ static void ngx_quic_free_frame(ngx_conn
 
 static void ngx_quic_congestion_ack(ngx_connection_t *c,
     ngx_quic_frame_t *frame);
-static void ngx_quic_congestion_lost(ngx_connection_t *c, ngx_msec_t sent);
+static void ngx_quic_congestion_lost(ngx_connection_t *c,
+    ngx_quic_frame_t *frame);
 
 
 static SSL_QUIC_METHOD quic_method = {
@@ -3627,9 +3628,11 @@ ngx_quic_send_frames(ngx_connection_t *c
                 ngx_del_timer(&qc->pto);
             }
             ngx_add_timer(&qc->pto, ngx_quic_pto(c, ctx));
+
+            start->plen = len;
         }
 
-        qc->congestion.in_flight += out.len;
+        qc->congestion.in_flight += len;
 
         ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
                        "quic congestion send if:%uz",
@@ -3783,12 +3786,11 @@ ngx_quic_detect_lost(ngx_connection_t *c
                 q = ngx_queue_next(q);
 
                 ngx_queue_remove(&f->queue);
-                qc->congestion.in_flight -= f->len;
                 ngx_queue_insert_tail(&range, &f->queue);
 
             } while (q != ngx_queue_sentinel(&ctx->sent));
 
-            ngx_quic_congestion_lost(c, start->last);
+            ngx_quic_congestion_lost(c, start);
 
             if (ngx_quic_send_frames(c, ctx, &range) != NGX_OK) {
                 return NGX_ERROR;
@@ -4535,26 +4537,34 @@ ngx_quic_congestion_ack(ngx_connection_t
     ngx_quic_congestion_t  *cg;
     ngx_quic_connection_t  *qc;
 
+    if (f->plen == 0) {
+        return;
+    }
+
     qc = c->quic;
     cg = &qc->congestion;
 
-    cg->in_flight -= f->len;
+    cg->in_flight -= f->plen;
 
     timer = f->last - cg->recovery_start;
 
     if ((ngx_msec_int_t) timer <= 0) {
+        ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
+                       "quic congestion ack recovery win:%uz, ss:%uz, if:%uz",
+                       cg->window, cg->ssthresh, cg->in_flight);
+
         return;
     }
 
     if (cg->window < cg->ssthresh) {
-        cg->window += f->len;
+        cg->window += f->plen;
 
         ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
                        "quic congestion slow start win:%uz, ss:%uz, if:%uz",
                        cg->window, cg->ssthresh, cg->in_flight);
 
     } else {
-        cg->window += qc->tp.max_udp_payload_size * f->len / cg->window;
+        cg->window += qc->tp.max_udp_payload_size * f->plen / cg->window;
 
         ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
                        "quic congestion avoidance win:%uz, ss:%uz, if:%uz",
@@ -4572,18 +4582,28 @@ ngx_quic_congestion_ack(ngx_connection_t
 
 
 static void
-ngx_quic_congestion_lost(ngx_connection_t *c, ngx_msec_t sent)
+ngx_quic_congestion_lost(ngx_connection_t *c, ngx_quic_frame_t *f)
 {
     ngx_msec_t              timer;
     ngx_quic_congestion_t  *cg;
     ngx_quic_connection_t  *qc;
 
+    if (f->plen == 0) {
+        return;
+    }
+
     qc = c->quic;
     cg = &qc->congestion;
 
-    timer = sent - cg->recovery_start;
+    cg->in_flight -= f->plen;
+
+    timer = f->last - cg->recovery_start;
 
     if ((ngx_msec_int_t) timer <= 0) {
+        ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
+                       "quic congestion lost recovery win:%uz, ss:%uz, if:%uz",
+                       cg->window, cg->ssthresh, cg->in_flight);
+
         return;
     }
 
--- a/src/event/ngx_event_quic_transport.h
+++ b/src/event/ngx_event_quic_transport.h
@@ -248,6 +248,7 @@ struct ngx_quic_frame_s {
     enum ssl_encryption_level_t                 level;
     ngx_queue_t                                 queue;
     uint64_t                                    pnum;
+    size_t                                      plen;
     ngx_msec_t                                  first;
     ngx_msec_t                                  last;
     ssize_t                                     len;