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
1 change: 0 additions & 1 deletion quest/m2/cluster-routing/routes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ benchmarks.

## Required

- [A relay folds received routes incrementally](/quest/m2/cluster-routing/routes/relay-receive.md) - a received route batch costs the claims it changes, not the origin's size
- [Announcement availability](/quest/m2/cluster-routing/routes/availability.md) - announcements report availability, and a let-go is offline rather than END, in Rust and JS
- [js/net route layer](/quest/m2/cluster-routing/routes/js.md) - `js/net` encodes, decodes, and resolves the route layer
- [Route layer acceptance](/quest/m2/cluster-routing/routes/acceptance.md) - forwarding fixtures ported and the model deleted, incident fixtures, end-to-end checks, and benchmarks
Expand Down
28 changes: 0 additions & 28 deletions quest/m2/cluster-routing/routes/relay-receive.md

This file was deleted.

59 changes: 48 additions & 11 deletions rs/moq-net/benches/routes.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
//! What one change to an origin's own claims costs its lite-07 route node.
//! What one change costs a lite-07 route node, at the origin and at a relay hearing it.
//!
//! The node answers announce streams, each with its own interest, and each is sent
//! only the claims that changed among those its interest meets. Swept over the claims
//! the origin holds and the streams it answers: a cost that grows with the claims
//! rather than the streams the change reaches shows up as a slope. Sending a change
//! costs each stream it reaches its own batch, so the streams axis is expected to
//! grow; the claims axis is not.
//!
//! - watched: every stream watches the root, so each is sent the change.
//! - unwatched: every stream watches a prefix of its own, which the change misses.
//! - watched, unwatched: one change to the origin's own claims, swept over the claims
//! the origin holds and the streams it answers. Sending a change costs each stream
//! it reaches its own batch, so the streams axis is expected to grow; the claims
//! axis is not. In watched every stream watches the root, so each is sent the
//! change; in unwatched each watches a prefix of its own, which the change misses.
//! - received: a relay hears one batch from the origin and forwards it on, swept over
//! the claims the origin holds and the claims the batch changes. The changes axis is
//! expected to grow; the claims axis is not.
//! - lagging: a relay hears the origin on two streams, the second some one-claim
//! batches behind the first, and each hears its next batch. Swept over the claims
//! the origin holds and how far the second lags: neither axis is expected to grow.
//!
//! The route layer is crate-private, so this reaches it through the hidden `fuzz` module.
//!
Expand All @@ -20,6 +22,12 @@ use moq_net::fuzz;
/// `(claims, streams)` shapes.
const SHAPES: [(usize, usize); 4] = [(10, 10), (10_000, 10), (10, 1_000), (10_000, 1_000)];

/// `(claims, changes)` shapes for a relay hearing a batch.
const RECEIVED: [(usize, usize); 4] = [(100, 1), (10_000, 1), (100, 100), (10_000, 100)];

/// `(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)];

fn bench(c: &mut Criterion, name: &str, interest: fn(usize) -> String, sent: usize) {
let mut group = c.benchmark_group(format!("routes/{name}"));
for (claims, streams) in SHAPES {
Expand Down Expand Up @@ -52,5 +60,34 @@ fn bench_unwatched(c: &mut Criterion) {
bench(c, "unwatched", |i| format!("other/{i}"), 0);
}

criterion_group!(benches, bench_watched, bench_unwatched);
fn bench_received(c: &mut Criterion) {
let mut group = c.benchmark_group("routes/received");
for (claims, changes) in RECEIVED {
let id = BenchmarkId::from_parameter(format!("{claims}c_{changes}d"));
let mut fixture = None;
group.bench_function(id, |b| {
let relay = fixture.get_or_insert_with(|| fuzz::RouteRelay::heard(claims));
// One serving change per claim changed, and one forwarded batch.
b.iter(|| assert_eq!(relay.change(changes), changes + 1));
});
}
group.finish();
}

fn bench_lagging(c: &mut Criterion) {
let mut group = c.benchmark_group("routes/lagging");
for (claims, lag) in LAGGING {
let id = BenchmarkId::from_parameter(format!("{claims}c_{lag}l"));
let mut fixture = None;
group.bench_function(id, |b| {
let relay = fixture.get_or_insert_with(|| fuzz::RouteRelay::lagging(claims, lag));
// The first stream's change is served through both streams and forwarded;
// the second's older one changes nothing.
b.iter(|| assert_eq!(relay.step(), 3));
});
}
group.finish();
}

criterion_group!(benches, bench_watched, bench_unwatched, bench_received, bench_lagging);
criterion_main!(benches);
123 changes: 123 additions & 0 deletions rs/moq-net/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,129 @@ impl RouteNode {
}
}

/// A relay's lite-07 route node hearing one origin's claims on streams it asked for,
/// and forwarding them on a stream it answers, for the routes bench.
pub struct RouteRelay {
// Dropped first: a stream disconnects from its node on drop.
receive: Vec<crate::route::node::Stream>,
answer: crate::route::node::Stream,
#[allow(dead_code, reason = "held so the streams keep a node to talk to")]
node: crate::route::Node,
instance: crate::Instance,
claims: usize,
/// The origin's revision as the first stream last heard it.
rev: u64,
/// The one-claim batches the first stream heard that the second has yet to: each
/// revision and the claim it changed.
behind: std::collections::VecDeque<(u64, usize)>,
}

impl RouteRelay {
/// The origin's identity as the relay hears it.
const ORIGIN: u64 = 1;

/// A relay that already heard and forwarded the origin's `claims` claims under
/// `live/`, on each of `streams` streams.
fn new(claims: usize, streams: usize) -> Self {
let node = crate::route::Node::new(2, 2);
let answer = node.answer(crate::route::Link::default(), Path::empty()).unwrap();
let instance = crate::Instance::random();
let rev = claims as u64;
let advert = crate::route::Advert {
seqno: 0,
metric: 0,
down_only: false,
};
let receive = (0..streams)
.map(|_| {
let receive = node.receive(crate::route::Link::default(), Path::empty()).unwrap();
receive.route(Self::ORIGIN, Some(crate::route::Reach::Finite(advert)));
let snapshot = (0..claims)
.map(|i| (Self::path(i), Some(Self::claim(&instance, 0))))
.collect();
receive.batch(Self::ORIGIN, snapshot, Some(rev));
receive
})
.collect();
let relay = Self {
receive,
answer,
node,
instance,
claims,
rev,
behind: Default::default(),
};
relay.drain();
relay
}

/// A relay hearing the origin's `claims` claims on one stream.
pub fn heard(claims: usize) -> Self {
Self::new(claims, 1)
}

/// A relay hearing the origin's `claims` claims on two streams, the second `lag`
/// one-claim batches behind the first.
pub fn lagging(claims: usize, lag: usize) -> Self {
let mut relay = Self::new(claims, 2);
for _ in 0..lag {
relay.advance();
}
relay.drain();
relay
}

fn path(i: usize) -> Path {
Path::new(&format!("live/{i}")).unwrap()
}

fn claim(instance: &crate::Instance, cost: u64) -> crate::route::node::Claim {
crate::route::node::Claim {
instance: instance.clone(),
epoch: 0,
cost,
upstream: false,
learned: false,
}
}

/// Hear one batch updating the first `changes` claims, returning how many outputs
/// the relay queued: what it serves into its origin, and what it forwards.
pub fn change(&mut self, changes: usize) -> usize {
self.rev += 1;
let claim = Self::claim(&self.instance, self.rev);
let batch = (0..changes).map(|i| (Self::path(i), Some(claim.clone()))).collect();
self.receive[0].batch(Self::ORIGIN, batch, Some(self.rev));
self.drain()
}

/// The first stream hears the origin's next revision, which changes one claim.
fn advance(&mut self) {
self.rev += 1;
let i = self.rev as usize % self.claims;
let batch = vec![(Self::path(i), Some(Self::claim(&self.instance, self.rev)))];
self.receive[0].batch(Self::ORIGIN, batch, Some(self.rev));
self.behind.push_back((self.rev, i));
}

/// Each stream hears its next one-claim batch, the second still lagging, returning
/// how many outputs the relay queued.
pub fn step(&mut self) -> usize {
self.advance();
let (rev, i) = self.behind.pop_front().expect("the second stream lags");
let batch = vec![(Self::path(i), Some(Self::claim(&self.instance, rev)))];
self.receive[1].batch(Self::ORIGIN, batch, Some(rev));
self.drain()
}

fn drain(&self) -> usize {
(self.receive.iter().chain([&self.answer]))
.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
Loading
Loading