Skip to content

Commit 614adda

Browse files
committed
BUG/MEDIUM: quic: correct pacing perf by fixing qc_prep_pkts() return
qc_prep_pkts() is a QUIC transport level function which encodes one or several datagrams in a buffer before sending them. It returns the number of encoded datagram. This is especially important when pacing is used to ensure to limit packet bursts. This datagram accounting was not trivial as qc_prep_pkts() used several code paths depending on the condition of the current encoded packet. Thus, there were several places were the local variable dgram_cnt could have been incremented. This was implemented by the following commit : commit 5cb8f8a MINOR: quic: support a max number of built packet per send iteration However, there is a bug due to a missing increment when all frames from the current QEL have been encoded. In this case, the encoding continue in the same datagram to coalesce a futur packet. However, if this is the last QEL, encoding loop will then break. As first_pkt is not NULL, qc_txb_store() is called outside but dgram_cnt is yet not incremented. In particular, this causes qc_prep_pkts() to return 0 when there is only small STREAM frames to emit for application QEL. In qc_send(), this is interpreted as a value which prevents further emission for the current invokation. Thus, it may hurts performance, both without and with pacing. To fix this, removing multiple dgram_cnt increment. Now, it is modified only in a single place which should cover every case, and render the code easier to validate. The most notable case where the bug is visible is when using cubic with pacing without any burst, with quic-cc-algo cubic(,1). First, transfer bandwidth in average was suboptimal, with significant variation. Worst, it could sometimes fall dramatically for a particular stream without recovering before returning to an expected level on the next one. No need to backport.
1 parent af658e5 commit 614adda

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/quic_tx.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
696696
if (first_pkt && (first_pkt->type != QUIC_PACKET_TYPE_INITIAL ||
697697
wrlen >= QUIC_INITIAL_PACKET_MINLEN)) {
698698
qc_txb_store(buf, wrlen, first_pkt);
699-
++dgram_cnt;
700699
}
701700
TRACE_PROTO("could not prepare anymore packet", QUIC_EV_CONN_PHPKTS, qc, qel);
702701
break;
@@ -733,6 +732,12 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
733732
cur_pkt->flags |= QUIC_FL_TX_PACKET_COALESCED;
734733
}
735734

735+
/* If <dglen> is NULL at this stage, it means the built
736+
* packet is the first of a new datagram.
737+
*/
738+
if (!dglen)
739+
++dgram_cnt;
740+
736741
total += cur_pkt->len;
737742
dglen += cur_pkt->len;
738743
wrlen += cur_pkt->len;
@@ -766,8 +771,6 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
766771
prv_pkt = cur_pkt;
767772
dglen = 0;
768773

769-
++dgram_cnt;
770-
771774
/* man 7 udp UDP_SEGMENT
772775
* The segment size must be chosen such that at
773776
* most 64 datagrams are sent in a single call
@@ -781,7 +784,6 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf,
781784
wrlen = dglen = 0;
782785
padding = 0;
783786
prv_pkt = NULL;
784-
++dgram_cnt;
785787
gso_dgram_cnt = 0;
786788
}
787789

0 commit comments

Comments
 (0)