Skip to content

Commit 2659fdf

Browse files
authored
Update delivery_rate units for gcongestion (#2043)
* Update delivery_rate units for gcongestion * congestion test * expose typed bandwidth for delivery rate --------- Co-authored-by: Apoorv Kothari <[email protected]>
1 parent ce6287c commit 2659fdf

18 files changed

+168
-46
lines changed

quiche/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9046,6 +9046,9 @@ impl TransportParams {
90469046
#[doc(hidden)]
90479047
pub mod testing {
90489048
use super::*;
9049+
use crate::recovery::Sent;
9050+
use smallvec::smallvec;
9051+
use std::time::Instant;
90499052

90509053
pub struct Pipe {
90519054
pub client: Connection,
@@ -9555,6 +9558,27 @@ pub mod testing {
95559558

95569559
(cid, reset_token)
95579560
}
9561+
9562+
pub fn helper_packet_sent(pkt_num: u64, now: Instant, size: usize) -> Sent {
9563+
Sent {
9564+
pkt_num,
9565+
frames: smallvec![],
9566+
time_sent: now,
9567+
time_acked: None,
9568+
time_lost: None,
9569+
size,
9570+
ack_eliciting: true,
9571+
in_flight: true,
9572+
delivered: 0,
9573+
delivered_time: now,
9574+
first_sent_time: now,
9575+
is_app_limited: false,
9576+
tx_in_flight: 0,
9577+
lost: 0,
9578+
has_data: false,
9579+
pmtud: false,
9580+
}
9581+
}
95589582
}
95599583

95609584
#[cfg(test)]

quiche/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl Path {
509509
lost_bytes: self.recovery.bytes_lost(),
510510
stream_retrans_bytes: self.stream_retrans_bytes,
511511
pmtu: self.recovery.max_datagram_size(),
512-
delivery_rate: self.recovery.delivery_rate(),
512+
delivery_rate: self.recovery.delivery_rate().to_bytes_per_second(),
513513
}
514514
}
515515
}

quiche/src/recovery/gcongestion/bandwidth.rs renamed to quiche/src/recovery/bandwidth.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ impl Bandwidth {
119119
self.bits_per_second
120120
}
121121

122+
pub const fn to_bytes_per_second(self) -> u64 {
123+
self.bits_per_second / 8
124+
}
125+
122126
pub const fn from_kbits_per_second(k_bits_per_second: u64) -> Self {
123127
Bandwidth {
124128
bits_per_second: k_bits_per_second * 1_000,
@@ -177,10 +181,9 @@ mod tests {
177181
fn constructors() {
178182
// Internal representation is bits per second.
179183
assert_eq!(Bandwidth::from_bytes_per_second(100).bits_per_second, 800);
180-
assert_eq!(
181-
Bandwidth::from_bytes_per_second(100).to_bits_per_second(),
182-
800
183-
);
184+
let bw = Bandwidth::from_bytes_per_second(100);
185+
assert_eq!(bw.to_bits_per_second(), 800);
186+
assert_eq!(bw.to_bytes_per_second(), 100);
184187

185188
// kbits == 1000 bits
186189
assert_eq!(

quiche/src/recovery/congestion/bbr/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,13 @@ mod tests {
405405
assert_eq!(sender.congestion_window, cwnd_prev + mss * 5);
406406
assert_eq!(sender.bytes_in_flight, 0);
407407
assert_eq!(
408-
sender.delivery_rate(),
408+
sender.delivery_rate().to_bytes_per_second(),
409409
((mss * 5) as f64 / rtt.as_secs_f64()) as u64
410410
);
411-
assert_eq!(sender.bbr_state.btlbw, sender.delivery_rate());
411+
assert_eq!(
412+
sender.bbr_state.btlbw,
413+
sender.delivery_rate().to_bytes_per_second()
414+
);
412415
}
413416

414417
#[test]

quiche/src/recovery/congestion/bbr/per_ack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ pub fn bbr_update_control_parameters(
7575
fn bbr_update_btlbw(r: &mut Congestion, packet: &Acked, _bytes_in_flight: usize) {
7676
bbr_update_round(r, packet);
7777

78-
if r.delivery_rate() >= r.bbr_state.btlbw ||
78+
if r.delivery_rate().to_bytes_per_second() >= r.bbr_state.btlbw ||
7979
!r.delivery_rate.sample_is_app_limited()
8080
{
8181
// Since minmax filter is based on time,
8282
// start_time + (round_count as seconds) is used instead.
8383
r.bbr_state.btlbw = r.bbr_state.btlbwfilter.running_max(
8484
BTLBW_FILTER_LEN,
8585
r.bbr_state.start_time + Duration::from_secs(r.bbr_state.round_count),
86-
r.delivery_rate(),
86+
r.delivery_rate().to_bytes_per_second(),
8787
);
8888
}
8989
}

quiche/src/recovery/congestion/bbr2/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,13 @@ mod tests {
757757
assert_eq!(r.cwnd(), cwnd_prev + mss * 5);
758758
assert_eq!(r.bytes_in_flight, 0);
759759
assert_eq!(
760-
r.delivery_rate(),
760+
r.delivery_rate().to_bytes_per_second(),
761761
((mss * 5) as f64 / rtt.as_secs_f64()) as u64
762762
);
763-
assert_eq!(r.congestion.bbr2_state.full_bw, r.delivery_rate());
763+
assert_eq!(
764+
r.congestion.bbr2_state.full_bw,
765+
r.delivery_rate().to_bytes_per_second()
766+
);
764767
}
765768

766769
#[test]

quiche/src/recovery/congestion/bbr2/per_ack.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,9 @@ fn bbr2_adapt_upper_bounds(r: &mut Congestion, now: Instant) {
428428
}
429429

430430
// TODO: what's rs.bw???
431-
if r.delivery_rate() > r.bbr2_state.bw_hi {
432-
r.bbr2_state.bw_hi = r.delivery_rate();
431+
let delivery_rate = r.delivery_rate().to_bytes_per_second();
432+
if delivery_rate > r.bbr2_state.bw_hi {
433+
r.bbr2_state.bw_hi = delivery_rate;
433434
}
434435

435436
if r.bbr2_state.state == BBR2StateMachine::ProbeBWUP {
@@ -569,7 +570,7 @@ fn bbr2_start_round(r: &mut Congestion) {
569570
pub fn bbr2_update_max_bw(r: &mut Congestion, packet: &Acked) {
570571
bbr2_update_round(r, packet);
571572

572-
if r.delivery_rate() >= r.bbr2_state.max_bw ||
573+
if r.delivery_rate().to_bytes_per_second() >= r.bbr2_state.max_bw ||
573574
!r.delivery_rate.sample_is_app_limited()
574575
{
575576
let max_bw_filter_len = r
@@ -581,7 +582,7 @@ pub fn bbr2_update_max_bw(r: &mut Congestion, packet: &Acked) {
581582
max_bw_filter_len,
582583
r.bbr2_state.start_time +
583584
Duration::from_secs(r.bbr2_state.cycle_count),
584-
r.delivery_rate(),
585+
r.delivery_rate().to_bytes_per_second(),
585586
);
586587
}
587588
}

quiche/src/recovery/congestion/bbr2/per_loss.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ pub fn bbr2_update_latest_delivery_signals(r: &mut Congestion) {
106106

107107
// Near start of ACK processing.
108108
bbr.loss_round_start = false;
109-
bbr.bw_latest = bbr.bw_latest.max(r.delivery_rate.sample_delivery_rate());
109+
bbr.bw_latest = bbr
110+
.bw_latest
111+
.max(r.delivery_rate.sample_delivery_rate().to_bytes_per_second());
110112
bbr.inflight_latest =
111113
bbr.inflight_latest.max(r.delivery_rate.sample_delivered());
112114

@@ -121,7 +123,8 @@ pub fn bbr2_advance_latest_delivery_signals(r: &mut Congestion) {
121123

122124
// Near end of ACK processing.
123125
if bbr.loss_round_start {
124-
bbr.bw_latest = r.delivery_rate.sample_delivery_rate();
126+
bbr.bw_latest =
127+
r.delivery_rate.sample_delivery_rate().to_bytes_per_second();
125128
bbr.inflight_latest = r.delivery_rate.sample_delivered();
126129
}
127130
}

quiche/src/recovery/congestion/delivery_rate.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
use std::time::Duration;
3333
use std::time::Instant;
3434

35+
use crate::recovery::bandwidth::Bandwidth;
36+
3537
use super::Acked;
3638
use super::Sent;
3739

@@ -73,7 +75,7 @@ impl Default for Rate {
7375

7476
largest_acked: 0,
7577

76-
rate_sample: RateSample::default(),
78+
rate_sample: RateSample::new(),
7779
}
7880
}
7981
}
@@ -149,9 +151,11 @@ impl Rate {
149151

150152
if !interval.is_zero() {
151153
// Fill in rate_sample with a rate sample.
152-
self.rate_sample.delivery_rate =
153-
(self.rate_sample.delivered as f64 / interval.as_secs_f64())
154-
as u64;
154+
let bytes_per_second = (self.rate_sample.delivered as f64 /
155+
interval.as_secs_f64())
156+
as u64;
157+
self.rate_sample.bandwidth =
158+
Bandwidth::from_bytes_per_second(bytes_per_second);
155159
}
156160
}
157161
}
@@ -168,8 +172,8 @@ impl Rate {
168172
self.delivered
169173
}
170174

171-
pub fn sample_delivery_rate(&self) -> u64 {
172-
self.rate_sample.delivery_rate
175+
pub fn sample_delivery_rate(&self) -> Bandwidth {
176+
self.rate_sample.bandwidth
173177
}
174178

175179
pub fn sample_rtt(&self) -> Duration {
@@ -189,9 +193,10 @@ impl Rate {
189193
}
190194
}
191195

192-
#[derive(Default, Debug)]
196+
#[derive(Debug)]
193197
struct RateSample {
194-
delivery_rate: u64,
198+
// The sample delivery_rate in bytes/sec
199+
bandwidth: Bandwidth,
195200

196201
is_app_limited: bool,
197202

@@ -210,6 +215,22 @@ struct RateSample {
210215
rtt: Duration,
211216
}
212217

218+
impl RateSample {
219+
const fn new() -> Self {
220+
RateSample {
221+
bandwidth: Bandwidth::zero(),
222+
is_app_limited: false,
223+
interval: Duration::ZERO,
224+
delivered: 0,
225+
prior_delivered: 0,
226+
prior_time: None,
227+
send_elapsed: Duration::ZERO,
228+
ack_elapsed: Duration::ZERO,
229+
rtt: Duration::ZERO,
230+
}
231+
}
232+
}
233+
213234
#[cfg(test)]
214235
mod tests {
215236
use super::*;
@@ -288,7 +309,7 @@ mod tests {
288309
assert_eq!(r.congestion.delivery_rate.delivered(), 2400);
289310

290311
// Estimated delivery rate = (1200 x 2) / 0.05s = 48000.
291-
assert_eq!(r.delivery_rate(), 48000);
312+
assert_eq!(r.delivery_rate().to_bytes_per_second(), 48000);
292313
}
293314

294315
#[test]

quiche/src/recovery/congestion/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use debug_panic::debug_panic;
2828
use std::time::Instant;
2929

3030
use self::recovery::Acked;
31+
use super::bandwidth::Bandwidth;
3132
use super::RecoveryConfig;
3233
use super::Sent;
3334
use crate::recovery::rtt;
@@ -146,7 +147,8 @@ impl Congestion {
146147
}
147148
}
148149

149-
pub(crate) fn delivery_rate(&self) -> u64 {
150+
/// The most recent data delivery rate estimate.
151+
pub(crate) fn delivery_rate(&self) -> Bandwidth {
150152
self.delivery_rate.sample_delivery_rate()
151153
}
152154

quiche/src/recovery/congestion/recovery.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ use std::collections::VecDeque;
3434
use super::RecoveryConfig;
3535
use super::Sent;
3636

37-
use crate::recovery::HandshakeStatus;
38-
use crate::recovery::RecoveryOps;
39-
4037
use crate::packet::Epoch;
4138
use crate::ranges::RangeSet;
39+
use crate::recovery::Bandwidth;
40+
use crate::recovery::HandshakeStatus;
41+
use crate::recovery::RecoveryOps;
4242

4343
#[cfg(feature = "qlog")]
4444
use crate::recovery::QlogMetrics;
@@ -817,7 +817,8 @@ impl RecoveryOps for LegacyRecovery {
817817
self.rtt() + cmp::max(self.rtt_stats.rttvar * 4, GRANULARITY)
818818
}
819819

820-
fn delivery_rate(&self) -> u64 {
820+
/// The most recent data delivery rate estimate.
821+
fn delivery_rate(&self) -> Bandwidth {
821822
self.congestion.delivery_rate()
822823
}
823824

quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use std::time::Duration;
3333
use std::time::Instant;
3434

3535
use super::Acked;
36-
use crate::recovery::gcongestion::bandwidth::Bandwidth;
36+
use crate::recovery::gcongestion::Bandwidth;
3737
use crate::recovery::gcongestion::Lost;
3838

3939
use super::windowed_filter::WindowedFilter;

quiche/src/recovery/gcongestion/bbr2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ use std::time::Instant;
4040

4141
use network_model::BBRv2NetworkModel;
4242

43+
use crate::recovery::gcongestion::Bandwidth;
44+
4345
use self::mode::Mode;
4446
use self::mode::ModeImpl;
4547

46-
use super::bandwidth::Bandwidth;
4748
use super::bbr::SendTimeState;
4849
use super::Acked;
4950
use super::BbrBwLoReductionStrategy;

quiche/src/recovery/gcongestion/bbr2/network_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use std::ops::Add;
3232
use std::time::Duration;
3333
use std::time::Instant;
3434

35-
use crate::recovery::gcongestion::bandwidth::Bandwidth;
3635
use crate::recovery::gcongestion::bbr::BandwidthSampler;
3736
use crate::recovery::gcongestion::bbr2::Params;
37+
use crate::recovery::gcongestion::Bandwidth;
3838
use crate::recovery::gcongestion::Lost;
3939
use crate::recovery::rtt::RttStats;
4040
use crate::recovery::rtt::INITIAL_RTT;

quiche/src/recovery/gcongestion/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
pub mod bandwidth;
2827
mod bbr;
2928
mod bbr2;
3029
pub mod pacer;
@@ -34,8 +33,8 @@ use std::fmt::Debug;
3433
use std::str::FromStr;
3534
use std::time::Instant;
3635

37-
use self::bandwidth::Bandwidth;
3836
pub use self::recovery::GRecovery;
37+
use crate::recovery::bandwidth::Bandwidth;
3938

4039
use crate::recovery::rtt::RttStats;
4140
use crate::recovery::rtt::INITIAL_RTT;

quiche/src/recovery/gcongestion/pacer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
use std::time::Instant;
3232

33+
use crate::recovery::gcongestion::Bandwidth;
3334
use crate::recovery::rtt::RttStats;
3435
use crate::recovery::ReleaseDecision;
3536
use crate::recovery::ReleaseTime;
3637

37-
use super::bandwidth::Bandwidth;
3838
use super::Acked;
3939
use super::Congestion;
4040
use super::CongestionControl;

0 commit comments

Comments
 (0)