diff --git a/quest/m1/README.md b/quest/m1/README.md index b4ac1f6d833..10fb301a00b 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -153,7 +153,6 @@ blocks. The quests that gated m0 lines moved under them. - [Papercuts](/quest/m1/papercuts.md) - JS refuses to serve a broadcast it did not produce, and a uring test stops sleeping - [Front parking](/quest/m1/origin-front-parks.md) - an unroutable request waits on a front instead of re-asking on every route-table move - [Route wakes](/quest/m1/route-wakes.md) - a route change wakes only the fronts it can move, so pool churn stops scaling with served paths -- [Copy-walk bench](/quest/m1/admission-bench.md) - a front's walk over its copies on a route change is benchmarked over tracks and copies - [Publish channel count](/quest/m1/publish-audio-channel-count.md) - forcing a channel count on an Audio.Capture stops costing the subscriber gaps of silence - [JS request deadline](/quest/m1/js-request-deadline.md) - each JS request, PUBLISH_NAMESPACE included, has one fatal 10 s timer from create to answer and fails fast without stream credit, so nothing queues or retries - [Rust request credit](/quest/m1/rs-request-credit.md) - a moq-net request fails at once without stream credit instead of waiting diff --git a/quest/m1/admission-bench.md b/quest/m1/admission-bench.md deleted file mode 100644 index 4d8cb614c32..00000000000 --- a/quest/m1/admission-bench.md +++ /dev/null @@ -1,31 +0,0 @@ -# [S] Front copy-walk benchmark - -## Goal - -A benchmark sweeps tracks per front against copies per track for the walks a -front makes over its copies when its route changes, so a cost that grows with -the front shows up as a slope. - -## Plan - -Decided in the 2026-10-05 audit: re-scoped from the wildcard line's admission -walk, which no longer exists (`Provenance::admit`, `front.admit()`, and -`io.copies()` are on neither `main` nor the line branch), to the copy walk -#4741 put on `main`. The Wildcard blocker is dropped, since this code is on -`main`. - -- Since #4741 a front resumes route changes by reading the routes' copies. - `attach` and `source_closed` call `drain_copies` - (`rs/moq-net/src/model/front.rs`), which walks every track, and the driver - keeps the serving source's copies until End. Nothing benchmarks either. -- Extend `rs/moq-net/benches/origin.rs` (or `session.rs` if a session is - needed to drive it) with a route swap swept over tracks per front and copies - per track. -- If the slope matters, say so rather than optimizing here; - [Front deadlines](/quest/m1/front-deadline-index.md) owns per-track wakes. - -Public API: none. Wire: none. - -## Related - -- [Front deadlines](/quest/m1/front-deadline-index.md) - per-track wakes on the same front diff --git a/rs/moq-net/benches/origin.rs b/rs/moq-net/benches/origin.rs index 3572263806e..252acec3397 100644 --- a/rs/moq-net/benches/origin.rs +++ b/rs/moq-net/benches/origin.rs @@ -12,14 +12,17 @@ //! An equal-cost pool is swept the same way, over its members and the paths it //! already serves. //! +//! A route swap on one front is swept over its tracks and the copies each track +//! still holds from earlier routes. +//! //! Run with `cargo bench -p moq-net --bench origin`. use std::task::Poll; use std::time::Duration; -use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; +use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main}; use futures::FutureExt; -use moq_net::{Hop, Hops, Pattern, Patterns, Timestamp, announce, broadcast, kio, origin}; +use moq_net::{Epoch, Hop, Hops, Pattern, Patterns, Timestamp, announce, broadcast, kio, origin, track}; /// `(publishers, subscribers)` shapes for the fan-out benchmarks. const SHAPES: [(usize, usize); 3] = [(100, 10), (1_000, 100), (1_000, 1_000)]; @@ -684,6 +687,155 @@ fn bench_parked(c: &mut Criterion) { group.finish(); } +/// `(tracks, copies)` for [`bench_copy_walk`]: tracks one front is serving, and +/// route copies each of those tracks still holds when the route swaps. +/// +/// The single-copy points from 32 to 128 tracks show the per-track slope alone. +const COPY_WALK: [(usize, usize); 8] = [(1, 1), (1, 32), (32, 1), (64, 1), (128, 1), (8, 32), (32, 8), (64, 16)]; + +const COPY_PATH: &str = "room/live"; + +/// How long a splice may take before the bench treats it as stuck. +const COPY_WAIT: Duration = Duration::from_secs(5); + +/// One generation at [`COPY_PATH`], held so its copies stay subscribed. +struct Generation { + broadcast: broadcast::Producer, + tracks: Vec, +} + +impl Generation { + /// Create a hidden generation and leave a finished group on every track, so a + /// reader that does look has something to resume. + fn build(producer: &origin::Producer, tracks: usize) -> Self { + let broadcast = producer.create_broadcast(COPY_PATH).unwrap(); + let mut held = Vec::with_capacity(tracks); + for i in 0..tracks { + let track = broadcast.create_track(format!("{i}"), None).unwrap(); + let mut written = track.append_group().unwrap(); + written.write_frame(Timestamp::ZERO, b"f".as_ref()).unwrap(); + written.finish().unwrap(); + held.push(track); + } + Self { + broadcast, + tracks: held, + } + } + + /// Route the front to this generation without waiting. + fn route(&self, epoch: &Epoch) { + self.broadcast + .announce(origin::Route::default().with_epoch(epoch.clone())) + .unwrap(); + } + + /// Route the front to this generation and wait until every track is spliced. + /// + /// The wait ends on demand, which flips when the front subscribes the new + /// copy, before its splice. That bounds the splice only on a current-thread + /// runtime, where every local query is ready within the front poll that + /// splices it. + async fn announce(&self, epoch: &Epoch) { + self.route(epoch); + for track in &self.tracks { + tokio::time::timeout(COPY_WAIT, track.demand().used()) + .await + .expect("route swap did not splice") + .expect("replacement track closed"); + } + } +} + +/// A front serving [`COPY_PATH`], with `copies` route copies on each of its tracks. +struct CopyWalk { + epoch: Epoch, + _producer: origin::Producer, + _subscribers: Vec, + generations: Vec, + /// The generation the timed swap announces, built during setup. + next: Option, +} + +/// Build a front with `copies` already spliced onto each track. +/// +/// Subscribers are never polled. A poll drops a replaced copy once its groups +/// are delivered, and this measures the walk over the copies a swap still has. +/// The same is why every generation is kept: dropping one ends its copy. +async fn copy_walk(tracks: usize, copies: usize) -> CopyWalk { + assert!(copies >= 1, "a front holds at least the serving copy"); + let (producer, driver) = origin::Producer::new(origin::Config::default()); + tokio::spawn(moq_net::time::run(driver)); + let epoch = Epoch::mint(); + let first = Generation::build(&producer, tracks); + first.route(&epoch); + let resolved = tokio::time::timeout(COPY_WAIT, producer.consume().request_broadcast(COPY_PATH)) + .await + .expect("front did not resolve") + .expect("front refused"); + let mut subscribers = Vec::with_capacity(tracks); + for i in 0..tracks { + let track = resolved.track(&format!("{i}")).unwrap(); + let subscriber = tokio::time::timeout(COPY_WAIT, track.subscribe(None)) + .await + .expect("track did not splice") + .expect("subscribe failed"); + subscribers.push(subscriber); + } + let mut generations = Vec::with_capacity(copies + 1); + generations.push(first); + for _ in 1..copies { + let generation = Generation::build(&producer, tracks); + generation.announce(&epoch).await; + generations.push(generation); + } + CopyWalk { + next: Some(Generation::build(&producer, tracks)), + epoch, + _producer: producer, + _subscribers: subscribers, + generations, + } +} + +impl CopyWalk { + /// Swap in the prebuilt newer route at the same epoch. + /// + /// A local track's info is already known, so the front subscribes, walks + /// every track, and each reader walks its copies in one driver turn. + async fn swap(&mut self) { + let generation = self.next.take().expect("one swap per setup"); + generation.announce(&self.epoch).await; + self.generations.push(generation); + } +} + +/// A route swap on one front. Setup holds `copies` per track and builds the +/// next generation, untimed; the announce and splice are timed. Warm-up sizes +/// the iteration count from wall time, which includes that setup, so a large +/// front does not multiply it by a fast routine. +/// +/// The runtime must stay current-thread; see [`Generation::announce`]. +fn bench_copy_walk(c: &mut Criterion) { + let mut group = c.benchmark_group("origin/copy_walk"); + group.sample_size(10); + for (tracks, copies) in COPY_WALK { + group.throughput(Throughput::Elements(tracks as u64)); + group.bench_function(BenchmarkId::from_parameter(format!("{tracks}t_{copies}c")), |b| { + let runtime = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + b.iter_batched_ref( + || runtime.block_on(copy_walk(tracks, copies)), + |rig| runtime.block_on(rig.swap()), + BatchSize::PerIteration, + ); + }); + } + group.finish(); +} + criterion_group!( benches, bench_announce, @@ -698,6 +850,7 @@ criterion_group!( bench_pool_churn, bench_handoff, bench_relay, - bench_parked + bench_parked, + bench_copy_walk ); criterion_main!(benches);