Skip to content

Commit

Permalink
[pacer] spawn 2 full-sized packets at once
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuho committed Mar 9, 2024
1 parent 73fd022 commit fc7e0bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
28 changes: 15 additions & 13 deletions include/quicly/pacer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,7 @@ extern "C" {
/**
* Simple pacer. The design guarantees that the formula below is met for any given pacer-restricted period:
*
* flow_rate * duration + burst_credit <= bytes_sent < flow_rate * duration + burst_credit + mtu
*
* where `burst_credit` is defined as:
*
* burst_credit = max((9 * mtu + 1) - flow_rate, 0)
*
* and that the sender never sends more than max(10*mtu, flow_rate) per every time slice.
* flow_rate * duration + 8 * mtu <= bytes_sent < flow_rate * duration + 10 * mtu
*/
typedef struct st_quicly_pacer_t {
/**
Expand All @@ -52,7 +46,8 @@ typedef struct st_quicly_pacer_t {
size_t bytes_sent;
} quicly_pacer_t;

#define QUICLY_PACER_CALC_BURST_BYTES(mtu) ((size_t)(mtu)*9 + 1)
#define QUICLY_PACER_BURST_LOW 8 /* lower bound in packets */
#define QUICLY_PACER_BURST_HIGH 10 /* high bound in packets */

/**
* resets the pacer
Expand Down Expand Up @@ -86,7 +81,7 @@ inline void quicly_pacer_reset(quicly_pacer_t *pacer)
inline int64_t quicly_pacer_can_send_at(quicly_pacer_t *pacer, uint32_t bytes_per_msec, uint16_t mtu)
{
/* return "now" if we have room in current msec */
size_t burst_size = QUICLY_PACER_CALC_BURST_BYTES(mtu);
size_t burst_size = QUICLY_PACER_BURST_LOW * mtu + 1;
size_t burst_credit = burst_size > bytes_per_msec ? burst_size - bytes_per_msec : 0;
if (pacer->bytes_sent < bytes_per_msec + burst_credit)
return 0;
Expand All @@ -106,8 +101,8 @@ inline uint64_t quicly_pacer_get_window(quicly_pacer_t *pacer, int64_t now, uint
if (now < can_send_at)
return 0;

/* Calculate burst window, as max(10mtu, bytes_per_msec) */
size_t burst_window = QUICLY_PACER_CALC_BURST_BYTES(mtu);
/* Calculate the upper bound of burst window (the size is later rounded up) */
size_t burst_window = (QUICLY_PACER_BURST_HIGH - 1) * mtu + 1;
if (burst_window < bytes_per_msec)
burst_window = bytes_per_msec;

Expand All @@ -118,11 +113,18 @@ inline uint64_t quicly_pacer_get_window(quicly_pacer_t *pacer, int64_t now, uint
uint64_t window, delta = (now - pacer->at) * bytes_per_msec;
if (pacer->bytes_sent > delta) {
pacer->bytes_sent -= delta;
window = burst_window > pacer->bytes_sent ? burst_window - pacer->bytes_sent : 1;
if (burst_window > pacer->bytes_sent) {
window = (burst_window - pacer->bytes_sent + mtu - 1) / mtu;
if (window < 2)
window = 2;
} else {
window = 2;
}
} else {
pacer->bytes_sent = 0;
window = burst_window;
window = (burst_window + mtu - 1) / mtu;
}
window *= mtu;

pacer->at = now;

Expand Down
23 changes: 10 additions & 13 deletions t/pacer.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,23 @@ static void test_medium(void)

static void test_slow(void)
{
const uint32_t bytes_per_msec = 500; /* one packet every 2.4ms */
const uint32_t bytes_per_msec = 700;
quicly_pacer_t pacer;
int64_t now = 1;

quicly_pacer_reset(&pacer);

now = test_pattern(&pacer, now, bytes_per_msec,
(const struct pattern[]){
{1, 10 * mtu, 10 * mtu}, /* borrow 1199 bytes */
{4, 1 * mtu, 1 * mtu}, /* borrowing 899 bytes, after 3ms */
{6, 1 * mtu, 1 * mtu}, /* borrowing 1099 bytes */
{9, 1 * mtu, 1 * mtu}, /* borrowing 799 bytes, after 3ms */
{11, 1 * mtu, 1 * mtu}, /* borrowing 999 bytes */
{13, 1 * mtu, 1 * mtu}, /* borrowing 1199 bytes */
{16, 1 * mtu, 1 * mtu}, /* borrowing 899 bytes, after 3ms */
{18, 1 * mtu, 1 * mtu}, /* borrowing 1099 bytes */
{21, 1 * mtu, 1 * mtu}, /* borrowing 799 bytes, after 3ms */
{23, 1 * mtu, 1 * mtu}, /* borrowing 999 bytes */
{25, 1 * mtu, 1 * mtu}, /* borrowing 1199 bytes */
{28, 1 * mtu, 1 * mtu}, /* borrowing 899 bytes, after 3ms */
{1, 10 * mtu, 10 * mtu}, /* borrow 12000 bytes */
{5, 2 * mtu, 2 * mtu}, /* borrowing 11600 bytes after 4ms */
{8, 2 * mtu, 2 * mtu}, /* borrowing 11900 bytes after 3ms */
{12, 2 * mtu, 2 * mtu}, /* borrowing 11500 bytes after 4ms */
{15, 2 * mtu, 2 * mtu}, /* borrowing 11800 bytes after 3ms */
{19, 2 * mtu, 2 * mtu}, /* borrowing 11400 bytes after 4ms */
{22, 2 * mtu, 2 * mtu}, /* borrowing 11700 bytes after 3ms */
{25, 2 * mtu, 2 * mtu}, /* borrowing 12000 bytes after 3ms */
{29, 2 * mtu, 2 * mtu}, /* borrowing 11600 bytes after 4ms */
{0},
});
}
Expand Down

0 comments on commit fc7e0bd

Please sign in to comment.