Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quest/m0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ a published `@moq/watch` break.

## Required

- [Expiry wakes](/quest/m0/expiry-wakes.md) - an appended group wakes only the parked reads it expires, so a 2.5 ms-frame publisher with 2 s of parked serves stays near idle and the Python and Go interop rows pass
- [Held group wakes](/quest/m0/held-group-wakes.md) - a group held across a route switch is woken when its successor's first timestamp or abort makes it stale, not at the next unrelated append
- [Draft-22 LOCATION_FILTER](/quest/m0/ietf-location-filter-22.md) - moqt-22 LOCATION_FILTER carries its type instead of a Length in Rust and JS, so a draft-22 peer reads our Next Object correctly
- [Request caps](/quest/m0/request-caps.md) - lite message sizes, IETF request IDs, and per-session announces and subscriptions are bounded
- [Prefix route fronts](/quest/m0/prefix-route-fronts.md) - a prefix route cannot be made to mint one front per requested path
Expand Down
66 changes: 0 additions & 66 deletions quest/m0/expiry-wakes.md

This file was deleted.

31 changes: 31 additions & 0 deletions quest/m0/held-group-wakes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# [S] A group held across a route switch wakes when it goes stale

## Goal

A group held across a route switch is woken when it goes stale: its
successor's first timestamp, its successor's abort, or a newer group's first
timestamp moving the edge. Today it waits for the next unrelated append.

## Plan

Split from the expiry-wakes quest, which landed the deadline index
(`model::expiry::Wakes`, owned by `cache::Track`) for `GroupServe` reads.

`Recover::poll` in `rs/moq-net/src/model/resume.rs` gives up a held group on
an old route through `Consumer::poll_stale`, which registers only on the
track state. Register the held group in the same `Wakes` index instead. One
mechanism, not a per-reader helper beside the index. Two differences the
index must carry: an entry can wait on its successor's first stamp with no
deadline yet, and Recover's entry lives in the serving copy's index (a
different track from the one holding the group), so it moves when the route
changes.

Tests: add #4950's `a_group_no_route_continues_wakes_when_its_successor_is_stamped`
to `resume.rs` (it would fail today), and extend it to the successor aborting
and a newer group stamping the edge.

Public API: none. Wire: none.

## Closes

- [#4950](https://github.com/moq-dev/moq/issues/4950) - a group held across a route switch is not woken when its successor gets its first timestamp
112 changes: 79 additions & 33 deletions rs/moq-net/benches/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
//! `track_subscriber_join` measures a burst of viewers joining one track: each join
//! registers in the subscription list, so any per-join walk of it shows up as a slope.
//!
//! `track_parked_read` appends past a backlog of reads parked on their drift budget:
//! each append must wake only the reads it can expire, so waking the backlog shows up
//! as a slope over it.
//!
//! Run with `cargo bench -p moq-net --bench track`.

use std::hint::black_box;
Expand Down Expand Up @@ -389,43 +393,85 @@ fn bench_subscriber_join(c: &mut Criterion) {
group.finish();
}

/// Parked reads re-judge their reach, including the successor's abort waiter.
/// Sweep readers and cached groups so added per-reader scans show up as a slope.
/// Queues a parked read as woken, so the bench visits only what an append wakes.
struct Woken {
read: usize,
queue: Arc<std::sync::Mutex<Vec<usize>>>,
}

impl std::task::Wake for Woken {
fn wake(self: Arc<Self>) {
self.wake_by_ref();
}

fn wake_by_ref(self: &Arc<Self>) {
self.queue.lock().unwrap().push(self.read);
}
}

/// One append past a backlog of parked reads, one per group like a publisher's parked
/// group streams, re-polling whatever it wakes. Swept over the backlog so a per-append
/// cost that grows with the parked reads shows up as a slope.
fn bench_parked_read(c: &mut Criterion) {
let mut group = c.benchmark_group("track_parked_read");
for cached in [8, 64, 512] {
for readers in [1, 8, 64] {
let broadcast = broadcast::Info::default().produce();
let track = broadcast.create_track("bench", None).unwrap();
let mut head = track.append_group().unwrap();
head.write_frame(Timestamp::ZERO, Bytes::from_static(b"head")).unwrap();
for _ in 1..cached {
let mut next = track.append_group().unwrap();
next.write_frame(Timestamp::ZERO, Bytes::from_static(b"next")).unwrap();
next.finish().unwrap();
}
let waiters: Vec<_> = (0..readers).map(|_| kio::Waiter::noop()).collect();
let mut held: Vec<_> = waiters
.iter()
.map(|waiter| {
let mut sub =
track.subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(1)));
let Poll::Ready(Ok(Some(mut head))) = sub.poll_recv_group(waiter) else {
panic!("head is cached");
};
assert!(matches!(head.poll_read_frame(waiter), Poll::Ready(Ok(Some(_)))));
head
})
.collect();
group.throughput(Throughput::Elements(readers as u64));
group.bench_function(BenchmarkId::new(format!("cached_{cached}"), readers), |b| {
b.iter(|| {
for (head, waiter) in held.iter_mut().zip(&waiters) {
assert!(black_box(head.poll_read_frame(waiter)).is_pending());
group.throughput(Throughput::Elements(1));
for parked in [8, 64, 512] {
group.bench_function(BenchmarkId::from_parameter(parked), |b| {
b.iter_custom(|iterations| {
let broadcast = broadcast::Info::default().produce();
let track = broadcast.create_track("bench", None).unwrap();
// Long enough that no read expires, so every append measures the same backlog.
let mut sub = track.subscribe(track::Subscription::default().with_max_delay(Duration::from_secs(3600)));
let mut micros = 0;
let mut open = Vec::with_capacity(parked);
let queue = Arc::new(std::sync::Mutex::new(Vec::new()));
let mut reads: Vec<_> = (0..parked)
.map(|read| {
let mut group = track.append_group().unwrap();
group
.write_frame(Timestamp::from_micros(micros).unwrap(), Bytes::from_static(b"x"))
.unwrap();
micros += 2500;
// Left open, so its read parks instead of ending.
open.push(group);

let woken = Woken {
read,
queue: queue.clone(),
};
let waiter = kio::Waiter::new(std::task::Waker::from(Arc::new(woken)));
let Poll::Ready(Ok(Some(mut read))) = sub.poll_recv_group(&waiter) else {
panic!("the group is cached");
};
assert!(matches!(read.poll_read_frame(&waiter), Poll::Ready(Ok(Some(_)))));
assert!(read.poll_read_frame(&waiter).is_pending());
(waiter, read)
})
.collect();

let mut woken = Vec::new();
let mut repoll = |reads: &mut Vec<(kio::Waiter, moq_net::group::Consumer)>| {
std::mem::swap(&mut woken, &mut *queue.lock().unwrap());
for read in woken.drain(..) {
let (waiter, read) = &mut reads[read];
assert!(black_box(read.poll_read_frame(waiter)).is_pending());
}
});
};
// Each append above woke the reads before it: park them again.
repoll(&mut reads);

let start = Instant::now();
for _ in 0..iterations {
let mut next = track.append_group().unwrap();
next.write_frame(Timestamp::from_micros(micros).unwrap(), Bytes::from_static(b"x"))
.unwrap();
next.finish().unwrap();
micros += 2500;
repoll(&mut reads);
}
start.elapsed()
});
}
});
}
group.finish();
}
Expand Down
4 changes: 2 additions & 2 deletions rs/moq-net/src/lite/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,7 @@ mod serve_group_test {

relay.run.update(lite::SubscribeUpdate {
priority: 0,
max_age: Duration::from_secs(30),
max_delay: Duration::from_secs(30),
start_group: None,
end_group: None,
start_frame: 0,
Expand All @@ -3519,7 +3519,7 @@ mod serve_group_test {

relay.run.update(lite::SubscribeUpdate {
priority: 0,
max_age: Duration::from_secs(30),
max_delay: Duration::from_secs(30),
start_group: None,
end_group: None,
start_frame: 0,
Expand Down
12 changes: 11 additions & 1 deletion rs/moq-net/src/model/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, OnceLock, Weak};
use std::time::Duration;

use super::group;
use super::track::{self, TrackState};
use super::{expiry, group};

/// Fixed bookkeeping charged per cached group on top of its frame payload bytes.
///
Expand Down Expand Up @@ -498,6 +498,10 @@ pub(crate) struct Track {
// This account's slot in the pool's sweep registry, absent when the pool has no
// expiry window (nothing is registered) or for the detached default account.
sweep: OnceLock<usize>,

// The track's reads parked on their drift budget. Here because this account is the
// link every group's frame writes already follow back to the track.
wakes: expiry::Wakes,
}

impl Track {
Expand All @@ -510,6 +514,7 @@ impl Track {
expiry_cursor: AtomicUsize::new(0),
state,
sweep: OnceLock::new(),
wakes: Default::default(),
});
if let Some(key) = track.pool.register(&track) {
let _ = track.sweep.set(key);
Expand All @@ -522,6 +527,11 @@ impl Track {
&self.pool
}

/// The track's reads parked on their drift budget.
pub(crate) fn wakes(&self) -> &expiry::Wakes {
&self.wakes
}

/// Charge a new group's fixed overhead, returning its [`Charge`].
pub(crate) fn charge(self: &Arc<Self>) -> Charge {
self.pool.add(ENTRY_OVERHEAD);
Expand Down
Loading
Loading