diff --git a/quest/m1/README.md b/quest/m1/README.md index e9e6d9570c2..4d093d614fb 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -173,7 +173,6 @@ per-frame CPU growth since #5926. - [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut - [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18 and 22 - [Calibrate the paired nightly benchmarks](/quest/m1/bench-ci.md) - A/A and deliberately slowed Nightly runs set the paired comparison's threshold, so its regression alerts can be trusted -- [The shared pacer holds its rate under 2 Mbit/s](/quest/m1/pacer-low-rate.md) - a rate-paced controller stops sending up to twice its pacing rate at low rates, landed with a BBR3 retune that keeps the probe budgets - [HLS and DASH segment conformance](/quest/m1/hls-conformance.md) - nightly ffprobe checks that advertised timing, sync flags, and bytes match the media served - [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; a group keeps a 32 MB tail, and readers behind it replay through paced flights or refresh - [A follower is told when the serving epochless route leaves](/quest/m1/epochless-leave-restart.md) - wire-level tests pin the restart a follower gets when the serving epochless route is withdrawn or dies while another remains diff --git a/quest/m1/pacer-low-rate.md b/quest/m1/pacer-low-rate.md deleted file mode 100644 index 7ead477b80f..00000000000 --- a/quest/m1/pacer-low-rate.md +++ /dev/null @@ -1,23 +0,0 @@ -# [S] The shared pacer holds its rate under 2 Mbit/s - -## Goal - -Under 2 Mbit/s, a rate-paced controller on moq-quic (BBR3 today, and any candidate that sets a pacing rate) sends at its pacing rate, not up to twice it. BBR3 is retuned in the same PR so the nightly probe scenarios, `competing_cubic` included, stay within their late-frame and overhead budgets. - -## Plan - -Found by [moq-dev/moq#7546](https://github.com/moq-dev/moq/pull/7546) (the GCC candidate). Below 2 Mbit/s the pacer's burst budget is one packet, and moq-quic checks a datagram's pace while the packet before it is still being built, so a batch of two leaves on one packet's credit. The shared pacer (`rs/moq-congestion/src/pacer.rs`) then forgets the overshoot instead of charging it to the next send. #7546 fixed it by carrying the overshoot as debt (its commit `b62e538b94`), which moved BBR3's nightly `competing_cubic` (`rs/moq-quic/src/tests/probe.rs`) to 441.5 late frames against an allowed 439.4, so it reverted the fix rather than retune BBR3 there. - -Decided 2026-11-01 (maintainer, follow-up planning after the 2026-11-01 /quest-afk run): m1, because the next release ships BBR3 as moq-quic's default and a 2x overshoot at low rates is a correctness bug in what it sends. Land the pacer fix and BBR3's retune together, so the nightly never runs one without the other. - -- Start from `b62e538b94`'s debt approach, with a unit test in `pacer.rs` that a batch outrunning a one-packet budget is charged to the next send, and the existing `aggregate_throughput_matches_controller_pacing_rate` swept below 2 Mbit/s. -- Retune where the change shifts BBR3's probing, not the budgets: the probe scenarios' budgets judge the probe, and loosening them to pass would hide the fix's effect. Report every probe scenario's paired late frames, p99, and overhead before and after, on the scenario's full seed set. -- `competing_cubic`'s 8-seed late budget is fragile on its own ([moq-dev/moq#7538](https://github.com/moq-dev/moq/pull/7538) found 28% of 8-seed windows fail it); its seed count is planned separately in [moq-dev/moq#7440](https://github.com/moq-dev/moq/pull/7440). Judge this change on a seed set large enough to separate it from that noise, not on whether seeds 1-8 pass. -- Re-run the realtime candidates' rows that pace below 2 Mbit/s ([GCC](https://github.com/moq-dev/moq/pull/7546), [BBR3 delay bound](https://github.com/moq-dev/moq/pull/7544), [SCReAMv2](https://github.com/moq-dev/moq/pull/7547)) for whichever have landed, and record the shift in the [epic](/quest/m2/quic-realtime/README.md). - -Public API: none. Wire: none. - -## Related - -- [Realtime uplink congestion control](/quest/m2/quic-realtime/README.md) - every candidate paces through this pacer -- [Probe up to a target bitrate](/quest/m2/probe/README.md) - its scenario budgets are what the retune must keep diff --git a/quest/m2/quic-realtime/README.md b/quest/m2/quic-realtime/README.md index 9e5ef198a75..8335b87c102 100644 --- a/quest/m2/quic-realtime/README.md +++ b/quest/m2/quic-realtime/README.md @@ -57,6 +57,17 @@ spike assumed no consumer; teleoperation uplinks are one): - Docs: inline only. The congestion-control lines in `doc/bin/cli.md` and `doc/lib/*` gain the new variant; no new page. +The shared pacer's low-rate correction and BBR3's one-datagram minimum send +quantum are implemented together in [moq-dev/moq#7606](https://github.com/moq-dev/moq/pull/7606). +GCC ([moq-dev/moq#7546](https://github.com/moq-dev/moq/pull/7546)) landed first, +so #7606 reran its in-tree row, `rises_to_target_under_gcc` (1 Mbit/s start, a +3 Mbit/s path opening to 12 Mbit/s), on all 8 seeds. The correction left it +unchanged: 1 late frame probing and baseline, the same p99, and the target +reached 5 s (1x) and 9 s (2x) after the path opened on every seed. The bake-off +must use the corrected pacer: earlier candidate rows below 2 Mbit/s, including +GCC's out-of-tree `tests::realtime` rows in #7546, can include up to 2x pacing +overshoot. + Remaining work once the candidates finish (this README's own job): - Run the shared comparison on the uplink presets: queuing delay p50/p95/p99, @@ -112,7 +123,6 @@ owns that feedback. ## Related -- [The shared pacer holds its rate under 2 Mbit/s](/quest/m1/pacer-low-rate.md) - every candidate paces through it, so its fix shifts their low-rate rows - [Per-stream and per-datagram deadlines](/quest/m2/quic-deadline.md) - also consumes the forward-delay estimate - [BBR media study](/quest/m2/quic-bbr-study.md) - BBR3 behavior under media, the baseline here - [Measure ECN on the backbone](/quest/m2/quic-ecn-measure.md) - decides whether SCReAMv2's L4S path is worth porting diff --git a/rs/moq-congestion/src/bbr3/mod.rs b/rs/moq-congestion/src/bbr3/mod.rs index 337eb210698..e40a0d0f467 100644 --- a/rs/moq-congestion/src/bbr3/mod.rs +++ b/rs/moq-congestion/src/bbr3/mod.rs @@ -587,7 +587,8 @@ impl Bbr3 { init.max_pacing_rate, init.now, ), - send_quantum: 2 * smss, /* we start high, but it will be adjusted in set_send_quantum */ + // Keep the first flight conservative until an ACK measures the path's RTT. + send_quantum: smss, pacing_gain: startup_pacing_gain, startup_pacing_gain, default_pacing_gain, @@ -1585,7 +1586,9 @@ impl Bbr3 { // C.pacing_rate is in bytes/sec, so multiplying by 1ms is dividing by 1000. let mut quantum = (self.pacing_rate / 1000.0) as u64; quantum = Ord::min(quantum, HIGH_PACE_MAX_QUANTUM); - quantum = Ord::max(quantum, 2 * self.smss); + // One datagram is enough at low rates. A two-datagram floor forces packet pairs + // even when earning that pair takes longer than the RTT. + quantum = Ord::max(quantum, self.smss); self.send_quantum = quantum; } @@ -4746,7 +4749,7 @@ mod test { /// packet size in bytes const MSS: u64 = 1200; /// bottleneck bandwidth: 8 Mbit/s (1 MB/s) in bytes/sec. Two constraints pin this: - /// - cruise pacing (~0.99*BW) times 1ms (~990 B) must stay under the `2*SMSS` + /// - cruise pacing (~0.99*BW) times 1ms (~990 B) must stay under the `SMSS` /// `set_send_quantum` floor, so `send_quantum` sits at that floor and `offload_budget` /// (send_quantum + delayed-ACK term) stays below `MinPipeCwnd` (4*SMSS); otherwise the /// floor can't bind. @@ -7234,14 +7237,15 @@ mod test { /// as the transport does until after the ACK callbacks. #[test] fn first_rtt_recalibrates_startup_pacing() { - for rtt_ns in [10 * MS, MS / 5] { + for rtt_ns in [MS / 5, 10 * MS, 100 * MS, 1000 * MS] { let mut sim = scripted(); + assert_eq!(sim.bbr.burst(), Some(sim.bbr.smss)); sim.round(0, 1, rtt_ns); assert_eq!(sim.bbr.pacing_rate, startup_rate(rtt_ns)); let quantum = (sim.bbr.pacing_rate / 1000.0) as u64; assert_eq!( sim.bbr.send_quantum, - quantum.clamp(2400, HIGH_PACE_MAX_QUANTUM) + quantum.clamp(1200, HIGH_PACE_MAX_QUANTUM) ); } } diff --git a/rs/moq-congestion/src/pacer.rs b/rs/moq-congestion/src/pacer.rs index 42675659f53..771b637cbc9 100644 --- a/rs/moq-congestion/src/pacer.rs +++ b/rs/moq-congestion/src/pacer.rs @@ -17,6 +17,10 @@ pub(crate) struct Pacer { /// Inputs [`Self::capacity`] was derived from, or `None` if it was derived from a pacing rate last_window_inputs: Option, tokens: u64, + /// Bytes sent past the available credit, repaid before earning new tokens. + /// The transport checks a datagram while the previous packet is still being built, + /// so one packet can leave beyond the burst budget. + debt: u64, max_bytes_per_second: Option, prev: Instant, } @@ -45,6 +49,7 @@ impl Pacer { capacity, last_window_inputs: Some(WindowInputs { window, mtu }), tokens: capacity, + debt: 0, max_bytes_per_second, prev: now, } @@ -52,7 +57,22 @@ impl Pacer { /// Record that a packet has been transmitted. pub(crate) fn on_transmit(&mut self, packet_length: u16) { - self.tokens = self.tokens.saturating_sub(packet_length.into()) + let bytes = u64::from(packet_length); + let spent = bytes.min(self.tokens); + self.tokens -= spent; + // Unpaced packets such as loss probes can spend beyond the budget too. Bound their + // repayment to one burst, while retaining the pending datagram's entire cost. + self.debt = (self.debt + bytes - spent).min(self.capacity.max(bytes)); + } + + /// Repays overshoot before adding earned credit to the burst budget. + fn refill(&mut self, earned: u64) { + let repaid = earned.min(self.debt); + self.debt -= repaid; + self.tokens = self + .tokens + .saturating_add(earned - repaid) + .min(self.capacity); } /// Return how long we need to wait before sending `bytes_to_send` @@ -90,11 +110,12 @@ impl Pacer { // here we cap the number of bytes sent at once during a burst self.tokens = self.capacity.min(self.tokens); + self.debt = self.capacity.min(self.debt); self.last_window_inputs = Some(inputs); } // if we can already send a packet, there is no need for delay - if self.tokens >= bytes_to_send { + if self.debt == 0 && self.tokens >= bytes_to_send { return None; } @@ -113,7 +134,7 @@ impl Pacer { let elapsed_rtts = time_elapsed.as_secs_f64() / smoothed_rtt.as_secs_f64(); let new_tokens = (window as f64 * 1.25 * elapsed_rtts).round() as u64; - self.tokens = self.tokens.saturating_add(new_tokens).min(self.capacity); + self.refill(new_tokens); // In the unlikely event that we're getting polled faster than tokens are generated, ensure // that `elapsed_rtts` can grow until we make progress. @@ -122,12 +143,12 @@ impl Pacer { } // if we can already send a packet, there is no need for delay - if self.tokens >= bytes_to_send { + if self.debt == 0 && self.tokens >= bytes_to_send { return None; } let unscaled_delay = smoothed_rtt - .checked_mul((bytes_to_send.max(self.capacity) - self.tokens) as _) + .checked_mul((bytes_to_send.max(self.capacity) - self.tokens + self.debt) as _) .unwrap_or(Duration::MAX) / window; @@ -163,6 +184,7 @@ impl Pacer { self.capacity = capacity; // here we cap the number of bytes sent at once during a burst self.tokens = self.capacity.min(self.tokens); + self.debt = self.capacity.min(self.debt); } // Invalidate the window path's cache: its inputs no longer describe `capacity`. self.last_window_inputs = None; @@ -175,14 +197,14 @@ impl Pacer { // pay for a single byte is carried over rather than discarded. Without this, a slow // rate polled frequently would never accumulate anything. if new_tokens > 0 { - self.tokens = self.tokens.saturating_add(new_tokens).min(self.capacity); + self.refill(new_tokens); self.prev = now; } // Capped at the burst budget so that a `bytes_to_send` exceeding the whole bucket is // still released eventually, rather than waiting for a level the bucket never reaches. let target = Ord::min(bytes_to_send, self.capacity); - if self.tokens >= target { + if self.debt == 0 && self.tokens >= target { return None; } @@ -190,7 +212,7 @@ impl Pacer { // the same interval on every poll and never retire, stalling the connection. // Round up, so the wait always earns the whole shortfall. At a high rate it can be under // a nanosecond, and truncating that to zero would re-arm the timer at `now` forever. - let deficit = target - self.tokens; + let deficit = target.saturating_sub(self.tokens) + self.debt; let nanos = (u128::from(deficit) * 1_000_000_000).div_ceil(u128::from(rate)); Some(now + Duration::from_nanos(u64::try_from(nanos).unwrap_or(u64::MAX))) } @@ -322,7 +344,8 @@ mod tests { /// Drives an always-backlogged sender through `pacer` for `duration` of simulated time the /// way `poll_transmit` does: send whenever the pacer allows it, otherwise jump to the instant - /// it asked to be polled again. Returns the bytes emitted. + /// it asked to be polled again. Each allowed send emits `batch` datagrams, including the + /// previous packet still being built when the transport checks the next. Returns bytes sent. fn bytes_sent_over( pacer: &mut Pacer, rtt: Duration, @@ -330,9 +353,10 @@ mod tests { start: Instant, duration: Duration, metrics: Rate, + batch: u16, ) -> u64 { - /// Guards against a pacer that never advances time; far above the ~8k polls a correct - /// pacer needs for one second at [`TEST_PACING_RATE`]. + /// Guards against a pacer that never advances time; above the ~170k polls a correct + /// pacer needs for ten seconds at [`TEST_PACING_RATE`]. const MAX_POLLS: u64 = 1_000_000; let deadline = start + duration; @@ -345,10 +369,12 @@ mod tests { polls < MAX_POLLS, "pacer made no progress: {sent} bytes emitted without reaching the deadline" ); - match pacer.delay(rtt, u64::from(mtu), mtu, at, metrics) { + match pacer.delay(rtt, u64::from(mtu) * u64::from(batch), mtu, at, metrics) { None => { - pacer.on_transmit(mtu); - sent += u64::from(mtu); + for _ in 0..batch { + pacer.on_transmit(mtu); + sent += u64::from(mtu); + } } Some(resume) => at = resume, } @@ -419,36 +445,119 @@ mod tests { } #[test] - fn aggregate_throughput_matches_controller_pacing_rate() { - const SECONDS: u64 = 1; + fn repays_a_packet_sent_past_the_burst_budget() { + let mtu = 1500; + let rtt = Duration::from_millis(50); + let start = Instant::now(); + for rate in [1_250, 12_500, 62_500, 125_000] { + let metrics = paced_metrics(1_000_000, rate); + let mut pacer = Pacer::new(rtt, 1_000_000, mtu, None, start); + assert_eq!( + pacer.delay(rtt, 2 * u64::from(mtu), mtu, start, metrics), + None + ); + assert_eq!(pacer.capacity, u64::from(mtu)); + pacer.on_transmit(mtu); + pacer.on_transmit(mtu); + let packet_time = Duration::from_nanos((u64::from(mtu) * 1_000_000_000).div_ceil(rate)); + let resume = start + packet_time * 2; + assert_eq!( + pacer.delay(rtt, u64::from(mtu), mtu, start, metrics), + Some(resume) + ); + // Earning one packet repays the overdraw; the next packet still needs credit. + assert_eq!( + pacer.delay(rtt, u64::from(mtu), mtu, start + packet_time, metrics), + Some(resume), + ); + assert_eq!(pacer.delay(rtt, u64::from(mtu), mtu, resume, metrics), None); + } + } + + #[test] + fn capacity_changes_bound_unpaced_debt() { let mtu = 1500; let rtt = Duration::from_millis(50); - let window = 2_000_000; - let metrics = paced_metrics(window, TEST_PACING_RATE); let start = Instant::now(); - let mut pacer = Pacer::new(rtt, window, mtu, None, start); + for rate in [1_250, 12_500, 62_500, 125_000] { + for explicit_rate in [false, true] { + let mut pacer = Pacer::new(rtt, 2_000_000, mtu, None, start); + burst_until_blocked( + &mut pacer, + rtt, + mtu, + start, + paced_metrics(2_000_000, TEST_PACING_RATE), + ) + .expect("the initial burst is finite"); + // Unpaced traffic can spend more than the pending datagram's credit. + for _ in 0..10 { + pacer.on_transmit(mtu); + } + assert!(pacer.debt > u64::from(mtu)); + + // The window path refills at 1.25 windows per RTT. + let metrics = Rate { + window: rate / 25, + pacing_rate: explicit_rate.then_some(rate), + }; + let resume = start + + Duration::from_nanos((2 * u64::from(mtu) * 1_000_000_000).div_ceil(rate)); + assert_eq!( + pacer.delay(rtt, u64::from(mtu), mtu, start, metrics), + Some(resume) + ); + assert_eq!(pacer.debt, u64::from(mtu)); + assert_eq!(pacer.delay(rtt, u64::from(mtu), mtu, resume, metrics), None); + } + } + } - let sent = bytes_sent_over( - &mut pacer, - rtt, - mtu, - start, - Duration::from_secs(SECONDS), - metrics, - ); + #[test] + fn aggregate_throughput_matches_controller_pacing_rate() { + const SECONDS: u64 = 10; - let expected = TEST_PACING_RATE * SECONDS; - // Slack covers the bucket the pacer starts full plus the trailing partial burst. - let slack = expected / 20; - assert!( - sent <= expected + slack, - "emitted {sent} bytes in {SECONDS}s, but pacing_rate allows only {expected}" - ); - assert!( - sent + slack >= expected, - "emitted {sent} bytes in {SECONDS}s, underrunning pacing_rate {expected}" - ); + let mtu = 1500; + let rtt = Duration::from_millis(50); + let window = 2_000_000; + let start = Instant::now(); + for rate in [ + 1_250, + 12_500, + 62_500, + 125_000, + 187_500, + 249_999, + 250_000, + TEST_PACING_RATE, + ] { + for batch in [1, 2] { + let metrics = paced_metrics(window, rate); + let mut pacer = Pacer::new(rtt, window, mtu, None, start); + let sent = bytes_sent_over( + &mut pacer, + rtt, + mtu, + start, + Duration::from_secs(SECONDS), + metrics, + batch, + ); + + let expected = rate * SECONDS; + // Initial credit and the final batch account for the only allowed overshoot. + let slack = rate_capacity(rate, mtu) + u64::from(batch) * u64::from(mtu); + assert!( + sent <= expected + slack, + "rate {rate}, batch {batch}: emitted {sent} bytes, allowed {expected} + {slack}" + ); + assert!( + sent + slack >= expected, + "rate {rate}, batch {batch}: emitted {sent} bytes, expected {expected}" + ); + } + } } #[test] @@ -807,6 +916,7 @@ mod tests { start, Duration::from_secs(SECONDS), metrics, + 1, ); // The configured ceiling binds even though the controller asks for far more.