From 78e2521103bd1c013deb5da52d5aef5b90d40818 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 10 Oct 2026 10:27:01 -0700 Subject: [PATCH 1/4] Claim quest/m1/cache-expiry-growth Co-Authored-By: GPT-6 From 3afac10551d03b0f8327a9df7f949ec82a5d150e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 10 Oct 2026 10:43:07 -0700 Subject: [PATCH 2/4] bench: remeasure expiry-only cache retention Co-Authored-By: GPT-6 --- quest/m1/README.md | 1 - quest/m1/cache-expiry-growth.md | 29 ----------------------------- rs/moq-net/benches/session.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 quest/m1/cache-expiry-growth.md diff --git a/quest/m1/README.md b/quest/m1/README.md index 4e5658eb63a..680c7cc70ae 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -141,7 +141,6 @@ session outcomes, and embedder refusals inside session outcomes. - [A/V clock](/quest/m1/av-clock.md) - the audio playhead drives Sync.reference while audio plays, through per-track sync handles - [Plan: watch worker](/quest/m1/plan-watch-worker.md) - prototype an invisible page worker against app-spawned workers, and land the jank harness that decides - [Watch worker](/quest/m1/watch-worker.md) - watch playback runs in a worker onto an OffscreenCanvas, so main-thread jank never stalls video or audio -- [Cache expiry growth](/quest/m1/cache-expiry-growth.md) - with the default pool, relay memory plateaus at the expiry window on every version - [Front deadlines](/quest/m1/front-deadline-index.md) - a front's per-event cost stops growing with its track count: an expiry index and per-track wakes, proven by a churn benchmark - [io_uring handshake deadline](/quest/m1/listener-deadlines.md) - the io_uring workers apply `listen.timeout` to the handshake - [HTTP listener deadlines](/quest/m1/listener-deadlines-http.md) - the HTTPS and internal listeners drop a connection with no request in flight for `listen.timeout` diff --git a/quest/m1/cache-expiry-growth.md b/quest/m1/cache-expiry-growth.md deleted file mode 100644 index 7bbe215a52c..00000000000 --- a/quest/m1/cache-expiry-growth.md +++ /dev/null @@ -1,29 +0,0 @@ -# [S] Cached groups expire under the default pool - -## Goal - -With the default cache pool, a relay's memory plateaus once groups start -reaching the expiry window, on every version, or the cause of continued -growth is found and fixed. - -## Plan - -In `session_delivery_broadcasts` with 4096 announced broadcasts and the -default unbounded pool (30 s expiry), RSS keeps climbing past the expiry -window on both wires (2026-09-25, Apple M4, sampled every 10 s): IETF -1.9 GB at 30 s and 4.4 GB at 120 s, lite-06 2.3 GB at 30 s and 3.5 GB at -120 s, both oscillating by a gigabyte between samples. With a 16 MiB bounded -pool both stay flat (0.5 GB IETF, 0.4 GB lite), so the retained bytes are -cached groups, not a leak elsewhere. An earlier run saw growth on IETF only, -but lite was then 30x slower per round, so it wrote far fewer groups; compare -by groups written, not by wall time. - -#4378 (after these runs) fixed one candidate cause: an ended track's latest -group was exempt from idle expiry and the pool sweep never reached an ended -track, so stale consumers pinned its groups. Re-measure on current `main` -first; if RSS now plateaus, delete this quest. - -Otherwise reproduce with a focused test. Unexpired groups at higher throughput, -expiry not running on some path, or groups held outside the pool's accounting -would each explain it. Fix what is actually wrong. Consider whether an -unbounded default is the right default for an origin at all. diff --git a/rs/moq-net/benches/session.rs b/rs/moq-net/benches/session.rs index 916a3a9cf4d..86b1bf09a35 100644 --- a/rs/moq-net/benches/session.rs +++ b/rs/moq-net/benches/session.rs @@ -11,6 +11,9 @@ //! route table they occupy, not a publisher writing into its own cache. //! //! `SESSION_ALLOCS=1` prints allocations per viewer-group instead of timing. +//! `SESSION_EXPIRY_ONLY=1` uses the standalone 30s-expiry pool and reports groups +//! written plus charged cache bytes every 10s during long profiling runs. Each round +//! advances the cache clock by a second, so the expiry window spans 30 rounds. //! //! `session_join_*` times a new viewer connecting, resolving a broadcast, and //! receiving its latest group, swept over what the relays already announce. @@ -282,7 +285,11 @@ impl Cluster { fn origin(&mut self, capacity: u64) -> (origin::Producer, cache::Pool) { self.next_hop += 1; let mut config = origin::Config::new(Hop::new(self.next_hop).unwrap()); - let pool = cache::Pool::new(cache::Config::default().with_capacity(capacity)); + let pool = cache::Pool::new(if std::env::var_os("SESSION_EXPIRY_ONLY").is_some() { + cache::Config::default().with_expiry(cache::DEFAULT_EXPIRY) + } else { + cache::Config::default().with_capacity(capacity) + }); config.pool = pool.clone(); let (producer, driver) = origin::Producer::new(config); support::harness::spawn(driver); @@ -341,6 +348,8 @@ struct Room { shape: Shape, /// Frames written so far, so paced rounds know where each group starts and ends. written: usize, + /// Groups finished so far across every watched broadcast. + groups: usize, /// The group each watched broadcast is writing, when paced. writing: Vec>, /// The group each viewer's subscriber is reading, when paced, flattened in viewer order. @@ -389,6 +398,7 @@ impl Room { payload: Bytes::from(vec![0; shape.frame]), shape, written: 0, + groups: 0, writing: Vec::new(), reading: Vec::new(), cache_now: moq_net::time::Instant::now(), @@ -455,6 +465,7 @@ impl Room { } } assert_eq!(bytes, self.shape.expected()); + self.groups += self.shape.burst * self.watched.len(); } /// One frame into every watched group and one frame out to every viewer, so each @@ -471,6 +482,9 @@ impl Room { *writing = None; } } + if last { + self.groups += self.watched.len(); + } let mut bytes = 0; let subscribers = self.viewers.iter_mut().flat_map(|viewer| &mut viewer.subscribers); @@ -492,11 +506,23 @@ impl Room { /// number of pools, not with the delivery being measured. async fn measure(&mut self, iters: u64) -> Duration { let mut elapsed = Duration::ZERO; + let report = std::env::var_os("SESSION_EXPIRY_ONLY").is_some(); + let began = Instant::now(); + let mut next_report = Duration::from_secs(10); for _ in 0..iters { self.tick(); let start = Instant::now(); self.round().await; elapsed += start.elapsed(); + if report && began.elapsed() >= next_report { + eprintln!( + "cache sample: elapsed={:.1}s groups={} charged={}", + began.elapsed().as_secs_f64(), + self.groups, + self.pools().map(cache::Pool::used).sum::() + ); + next_report += Duration::from_secs(10); + } } elapsed } From 1a0d0c337800eed953d436ca58c5087018365b6b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 10 Oct 2026 10:44:06 -0700 Subject: [PATCH 3/4] quest: link completed expiry measurement Co-Authored-By: GPT-6 --- quest/m1/cache-max-age.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quest/m1/cache-max-age.md b/quest/m1/cache-max-age.md index 5a9db9dedf8..deed13abefc 100644 --- a/quest/m1/cache-max-age.md +++ b/quest/m1/cache-max-age.md @@ -128,6 +128,6 @@ encoding change; Max Age semantics in the lite draft change. - [lite-07 Live flag](/quest/m1/lite-live.md) - its untimed `Live` start (the latest group) follows this rule instead: replay what is not stale - [JS track handover](/quest/m1/js-group-handover.md) - mirrors the failover rule in JS -- [Cache expiry growth](/quest/m1/cache-expiry-growth.md) - relay memory past the expiry window, in the same cache +- [Cache expiry growth](https://github.com/moq-dev/moq/pull/5241) - relay memory past the expiry window, in the same cache - [Generated @moq/net](/quest/m1/rs2ts/README.md) - retires js/net's hand-written model - [FETCH max-delay](/quest/m1/fetch-max-delay.md) - applies the shared rule to historical requests and reconciles native IETF retention clocks From 066de1e6d8e21b23e5bd39fcb793ea193df7cbeb Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 11 Oct 2026 09:50:39 -0700 Subject: [PATCH 4/4] quest: drop the completed expiry quest's reference Co-Authored-By: Claude Opus 5.5 --- quest/m1/cache-max-age.md | 1 - 1 file changed, 1 deletion(-) diff --git a/quest/m1/cache-max-age.md b/quest/m1/cache-max-age.md index deed13abefc..f2a88cc5a44 100644 --- a/quest/m1/cache-max-age.md +++ b/quest/m1/cache-max-age.md @@ -128,6 +128,5 @@ encoding change; Max Age semantics in the lite draft change. - [lite-07 Live flag](/quest/m1/lite-live.md) - its untimed `Live` start (the latest group) follows this rule instead: replay what is not stale - [JS track handover](/quest/m1/js-group-handover.md) - mirrors the failover rule in JS -- [Cache expiry growth](https://github.com/moq-dev/moq/pull/5241) - relay memory past the expiry window, in the same cache - [Generated @moq/net](/quest/m1/rs2ts/README.md) - retires js/net's hand-written model - [FETCH max-delay](/quest/m1/fetch-max-delay.md) - applies the shared rule to historical requests and reconciles native IETF retention clocks