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
18 changes: 18 additions & 0 deletions js/net/src/lite/floors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ test("a regressed route's certified view decides only while a live floor certifi
floors.join(NODE, lagging);
expect(floors.shows(NODE, lagging.view, Path.from("live/y"))).toBeUndefined();
});

test("a route that leaves or floors reshows only the routes whose prefix meets its own", () => {
const floors = new Floors();
const reshown: string[] = [];
const route = (prefix: string) => {
const { view } = carrier(prefix, 1n, [[`${prefix}/x`, A]]);
return { view, reshow: () => reshown.push(prefix) };
};
const routes = ["live/a", "live/a/b", "live", "live/c"].map(route);
for (const r of routes) floors.join(NODE, r);

floors.floor(NODE, routes[0]);
expect(reshown.sort()).toEqual(["live", "live/a/b"]);

reshown.length = 0;
floors.leave(NODE, routes[3]);
expect(reshown).toEqual(["live"]);
});
17 changes: 10 additions & 7 deletions js/net/src/lite/floors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export class Floors {
/**
* The route ended or its stream closed. What its floor certified stays while another route to
* the node may still carry a claim it decides; the last route takes the node's state with it.
* Every other route to the node is shown anew, since a path this one alone certified now shows
* what its streams carry.
* Every other route to the node whose prefix meets this one's is shown anew, since a path this
* one alone certified now shows what its streams carry; a route's claims lie within its prefix,
* so no other route's can change, and a session closing many prefixes costs each only its own.
*/
leave(node: bigint, carrier: Carrier): void {
const entry = this.#nodes.get(node);
Expand All @@ -107,7 +108,7 @@ export class Floors {
const { prefix, hidden, revision, claims } = carrier.view;
if (revision !== undefined) entry.retained.push({ prefix, hidden, revision, claims });
this.#prune(entry);
for (const other of entry.carriers) other.reshow();
for (const other of entry.carriers) if (meets(other.view.prefix, prefix)) other.reshow();
}

/**
Expand All @@ -123,17 +124,19 @@ export class Floors {
}

/**
* A route to `node` applied a batch at its floor: every other route to it is shown anew.
* Returns whether any other view of the node existed, in which case the route's own unchanged
* claims may have changed state too, even if this floor pruned it.
* A route to `node` applied a batch at its floor: every other route to it whose prefix meets
* this one's is shown anew, as in `leave`. Returns whether any other view of the node existed,
* in which case the route's own unchanged claims may have changed state too, even if this floor
* pruned it.
*/
floor(node: bigint, carrier: Carrier): boolean {
const entry = this.#nodes.get(node);
if (!entry) return false;
const retained = entry.retained.length;
this.#prune(entry);
if (entry.carriers.size === 1 && retained === 0) return false;
for (const other of entry.carriers) if (other !== carrier) other.reshow();
const prefix = carrier.view.prefix;
for (const other of entry.carriers) if (other !== carrier && meets(other.view.prefix, prefix)) other.reshow();
return true;
}

Expand Down
64 changes: 0 additions & 64 deletions quest/m0/ci/nightly-relay-session-hour.md

This file was deleted.

36 changes: 36 additions & 0 deletions quest/m0/nightly/lite06-join-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# [M] A lite-06 viewer joining a relay reads its first group again

## Goal

`relay_session_join_broadcasts` and `relay_session_join_stale` finish their
moq-lite-06 cells, as they did before
[moq-dev/moq#8476](https://github.com/moq-dev/moq/pull/8476), so
`Nightly (Relay session benchmarks)` (`just gh nightly rust-relay`) finishes
inside its hour with every cell.

## Plan

Found 2026-11-12 while timing the relay session group for
[moq-dev/moq#8555](https://github.com/moq-dev/moq/pull/8555). The first
moq-lite-06 cell of `relay_session_join_broadcasts`
(`relays=1/publishers=1/broadcasts=1/viewers=16`) and of
`relay_session_join_stale` never leaves its warm-up: the bench thread parks in
the cell's `join` loop (`rs/moq-net/benches/session/mod.rs`) at 0% CPU,
waiting on a join, watch, or the first group read that never completes. The
moq-transport and moq-lite-07 cells of the same groups finish in seconds, and
`relay_session_join_relays` finishes on every version.

`git bisect` over `c916855d16..75f00f92c8` (the 11-11 Nightly's commit, whose
lite-06 join cells finished in 0.2 s, to main on 2026-11-12) names
f3edb0b8d9 ([moq-dev/moq#8476](https://github.com/moq-dev/moq/pull/8476), "a
failed fetch below the end no longer holds it open") as the first hanging
commit. Reproduce with
`cargo bench -p moq-relay --features test-support --bench session -- --quick 'relay_session_join_broadcasts/moq-lite-06/'`.

Find which await hangs, reproduce it as a moq-net integration test of a
lite-06 viewer joining a relay that holds history, and fix the cause. A
viewer that never receives a group it subscribed to is a product bug, not
only a bench one, so do not skip the cells.

Then confirm a scheduled Nightly's relay session job finishes inside its
hour; never dispatch Nightly.
5 changes: 3 additions & 2 deletions quest/m2/cluster-routing/routes/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ Work:
publisher's routes as the model has it. Keep the reader's view a function
of what the router holds, computed incrementally the way `show` is today,
with the test build comparing it against the whole computation.
- Keep a session's teardown about linear in the prefixes it held, as
[the relay session hour](/quest/m0/ci/nightly-relay-session-hour.md) makes it.
- Keep a session's teardown about linear in the prefixes it held, as the
routes bench's `teardown` and `refollow` cells measure
(`rs/moq-net/benches/routes.rs`).
- What #8487 added to work around the old rule has no counterpart either:
`recompute`'s `prune` switch, which skips pruning on a change of hops or
RTT alone. Keep the qualified-key test in `infeasible` only if the new
Expand Down
45 changes: 43 additions & 2 deletions rs/moq-net/benches/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
//! another epoch, then back at the shared one, each confirmed. Swept over the claims
//! held and the streams answered: the streams axis is expected to grow, since each is
//! sent the claim; the claims axis is not.
//! - teardown: a node following one origin on a stream per prefix, as a viewer session
//! holding many announce prefixes does, closes them all at once. Swept over the
//! prefixes followed and the claims each holds: both axes are expected to grow, no
//! faster than the claims held.
//! - refollow: the same node closes one prefix's stream and opens it again. The claims
//! axis is expected to grow, since the stream hears its prefix's claims again; the
//! prefixes axis no faster than the prefixes held.
//!
//! The route layer is crate-private, so this reaches it through the `fuzz` module.
//!
//! Run with `cargo bench -p moq-net --features fuzz --bench routes`.

use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use criterion::{BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main};
use moq_net::fuzz;

/// `(claims, streams)` shapes.
Expand All @@ -33,6 +40,9 @@ const RECEIVED: [(usize, usize); 4] = [(100, 1), (10_000, 1), (100, 100), (10_00
/// `(claims, streams)` shapes for a relay holding back claims.
const HELD: [(usize, usize); 4] = [(10, 10), (10_000, 10), (10, 100), (10_000, 100)];

/// `(prefixes, claims)` shapes for a node following one origin per prefix.
const FOLLOWED: [(usize, usize); 4] = [(16, 1), (1_024, 1), (16, 16), (1_024, 16)];

/// `(claims, lag)` shapes for a relay hearing a stream that lags another.
const LAGGING: [(usize, usize); 4] = [(100, 1), (10_000, 1), (100, 100), (10_000, 10_000)];

Expand Down Expand Up @@ -111,12 +121,43 @@ fn bench_confirmed(c: &mut Criterion) {
group.finish();
}

fn bench_teardown(c: &mut Criterion) {
let mut group = c.benchmark_group("routes/teardown");
for (prefixes, claims) in FOLLOWED {
let id = BenchmarkId::from_parameter(format!("{prefixes}p_{claims}c"));
group.bench_function(id, |b| {
b.iter_batched(
|| fuzz::RouteFollower::new(prefixes, claims),
fuzz::RouteFollower::teardown,
BatchSize::PerIteration,
);
});
}
group.finish();
}

fn bench_refollow(c: &mut Criterion) {
let mut group = c.benchmark_group("routes/refollow");
for (prefixes, claims) in FOLLOWED {
let id = BenchmarkId::from_parameter(format!("{prefixes}p_{claims}c"));
let mut fixture = None;
group.bench_function(id, |b| {
let follower = fixture.get_or_insert_with(|| fuzz::RouteFollower::new(prefixes, claims));
// The reopened stream serves its prefix's claims into the origin again.
b.iter(|| assert_eq!(follower.refollow(), claims));
});
}
group.finish();
}

criterion_group!(
benches,
bench_watched,
bench_unwatched,
bench_received,
bench_lagging,
bench_confirmed
bench_confirmed,
bench_teardown,
bench_refollow
);
criterion_main!(benches);
82 changes: 82 additions & 0 deletions rs/moq-net/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,88 @@ impl RouteRelay {
}
}

/// A lite-07 route node following one origin on a stream per prefix, as a viewer
/// session holding many announce prefixes does, for the routes bench.
pub struct RouteFollower {
node: crate::route::Node,
/// Each prefix's stream, `None` only while [`Self::refollow`] replaces it.
streams: Vec<Option<crate::route::node::Stream>>,
instance: crate::Instance,
claims: usize,
/// The next stream [`Self::refollow`] replaces.
next: usize,
}

impl RouteFollower {
/// The origin's identity and revision as the node hears them.
const ORIGIN: u64 = 1;
const REV: u64 = 1;

/// A node following `prefixes` prefixes `live/{k}`, each holding `claims` claims.
pub fn new(prefixes: usize, claims: usize) -> Self {
let mut follower = Self {
node: crate::route::Node::new(2, 2),
streams: Vec::new(),
instance: crate::Instance::random(),
claims,
next: 0,
};
follower.streams = (0..prefixes).map(|k| Some(follower.follow(k))).collect();
follower.drain();
follower
}

/// Open the stream for prefix `k`, which hears the origin's route and snapshot.
fn follow(&self, k: usize) -> crate::route::node::Stream {
let prefix = Path::new(&format!("live/{k}")).unwrap();
let stream = self.node.receive(crate::route::Link::default(), prefix).unwrap();
let advert = crate::route::Advert {
seqno: 0,
metric: 0,
down_only: false,
rtt: None,
hops: [].into(),
};
stream.route(Self::ORIGIN, Some(crate::route::Reach::Finite(advert)));
let claim = crate::route::node::Claim {
instance: self.instance.clone(),
epoch: 0,
cost: 0,
upstream: false,
learned: false,
chain: crate::Hops::new(),
};
let snapshot = (0..self.claims)
.map(|j| (Path::new(&format!("live/{k}/{j}")).unwrap(), Some(claim.clone())))
.collect();
stream.batch(Self::ORIGIN, snapshot, Some(Self::REV));
stream
}

/// Close one prefix's stream and open it again, returning how many outputs the
/// node queued.
pub fn refollow(&mut self) -> usize {
let k = self.next % self.streams.len();
self.next += 1;
// Closed first, so the node lets go of the prefix before hearing it again.
drop(self.streams[k].take());
self.streams[k] = Some(self.follow(k));
self.drain()
}

/// Close every stream at once, as a session ending does.
pub fn teardown(self) {
let _closing = self.node.closing();
drop(self.streams);
}

fn drain(&self) -> usize {
(self.streams.iter().flatten())
.map(|stream| std::iter::from_fn(|| stream.try_output()).count())
.sum()
}
}

/// What a client session fed into an origin hears it should ask its peer about, for
/// the interests bench.
pub struct Interests(crate::model::Interests);
Expand Down
8 changes: 8 additions & 0 deletions rs/moq-net/src/lite/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ impl Publisher {
}
}

impl Drop for Publisher {
fn drop(&mut self) {
// Every announce stream closes with the session: disconnect them together.
let _closing = self.shared.origin.route_closing();
self.children = kio::Tasks::new();
}
}

impl Publisher {
/// The peer's latest PROBE target, or zero while it asks for none.
pub fn peer_target(&self) -> kio::Consumer<crate::bandwidth::Rate> {
Expand Down
3 changes: 3 additions & 0 deletions rs/moq-net/src/lite/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ impl Drop for SubscriberDriver {
// `abort` already recorded a session error when the driver failed. A driver
// dropped without that still has to name an end before its setup machines drop.
self.subscriber.note_end(&Error::Cancel);
// Every announce stream closes with the session: disconnect them together.
let _closing = self.subscriber.origin.route_closing();
self.announces = kio::Tasks::new();
}
}

Expand Down
Loading