delivery rate: fix where on_packet_sent() hook is called
Fix where `delivery_rate.on_packet_sent()` is called to be
after updating the time to send the packet. It will reduce the
chance that `rate_sample.interval` is shorter than `min_rtt`,
especailly useful for low latency (<1ms) network.
Also, when updating `first_time_sent` when the network is idle
(bytes_in_flight == 0), use the packet's timestamp. `now` may
be in the future.
diff --git a/quiche/src/recovery/delivery_rate.rs b/quiche/src/recovery/delivery_rate.rs
index 37c2aaf..59abf81 100644
--- a/quiche/src/recovery/delivery_rate.rs
+++ b/quiche/src/recovery/delivery_rate.rs
@@ -79,13 +79,11 @@
}
impl Rate {
- pub fn on_packet_sent(
- &mut self, pkt: &mut Sent, bytes_in_flight: usize, now: Instant,
- ) {
- // No packets in flight yet?
+ pub fn on_packet_sent(&mut self, pkt: &mut Sent, bytes_in_flight: usize) {
+ // No packets in flight.
if bytes_in_flight == 0 {
- self.first_sent_time = now;
- self.delivered_time = now;
+ self.first_sent_time = pkt.time_sent;
+ self.delivered_time = pkt.time_sent;
}
pkt.first_sent_time = self.first_sent_time;
diff --git a/quiche/src/recovery/mod.rs b/quiche/src/recovery/mod.rs
index 4011fe3..901c10e 100644
--- a/quiche/src/recovery/mod.rs
+++ b/quiche/src/recovery/mod.rs
@@ -273,9 +273,6 @@
self.largest_sent_pkt[epoch] =
cmp::max(self.largest_sent_pkt[epoch], pkt_num);
- self.delivery_rate
- .on_packet_sent(&mut pkt, self.bytes_in_flight, now);
-
if in_flight {
if ack_eliciting {
self.time_of_last_sent_ack_eliciting_pkt[epoch] = Some(now);
@@ -315,6 +312,10 @@
pkt.time_sent = self.get_packet_send_time();
+ // bytes_in_flight is already updated. Use previous value.
+ self.delivery_rate
+ .on_packet_sent(&mut pkt, self.bytes_in_flight - sent_bytes);
+
self.sent[epoch].push_back(pkt);
self.bytes_sent += sent_bytes;
@@ -1125,11 +1126,11 @@
impl std::fmt::Debug for Sent {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "pkt_num={:?} ", self.pkt_num)?;
- write!(f, "pkt_sent_time={:?} ", self.time_sent.elapsed())?;
+ write!(f, "pkt_sent_time={:?} ", self.time_sent)?;
write!(f, "pkt_size={:?} ", self.size)?;
write!(f, "delivered={:?} ", self.delivered)?;
- write!(f, "delivered_time={:?} ", self.delivered_time.elapsed())?;
- write!(f, "first_sent_time={:?} ", self.first_sent_time.elapsed())?;
+ write!(f, "delivered_time={:?} ", self.delivered_time)?;
+ write!(f, "first_sent_time={:?} ", self.first_sent_time)?;
write!(f, "is_app_limited={} ", self.is_app_limited)?;
write!(f, "has_data={} ", self.has_data)?;