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
59 changes: 27 additions & 32 deletions quest/m2/lite07-update-cost.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [M] A lite-07 SUBSCRIBE_UPDATE costs its edit on the publisher's session too
# [M] A lite-07 SUBSCRIBE_UPDATE costs its edit on a relay's front and in JS too

## Goal

Expand All @@ -8,41 +8,36 @@ lock every subscriber of the track shares, in Rust and JS alike.

## Plan

Left by the [range union fix](https://github.com/moq-dev/moq/pull/9045), which
made an update that leaves every range live cost nothing for the ranges, and
held the shared lock only for the ranges an edit moves. What remains is linear
in n on the session's own task for any update that edits a range or changes a
preference: n is bounded by one message's ranges, so this is CPU a peer spends
one small message to buy, not unbounded work.

- Rust: `TrackRun::update` (`rs/moq-net/src/lite/publisher.rs`) re-pins every
range, rebuilds its Range ID positions and `Bounds`, and hands the model a
whole `Subscription`. The model resolves ranges by position
(`track.resolved()`), so editing by Range ID means the model's ranges and
their resolutions are keyed rather than positional
(`rs/moq-net/src/model/track.rs`, `model/track/demand.rs`). A preference-only
update still clones the model's ranges.
Left by [#9134](https://github.com/moq-dev/moq/pull/9134), which made the
Rust publisher hand the model the edit by Range ID
(`track::Subscriber::edit`), keyed each subscriber's ranges with a change
log (`model/track/demand.rs` `Prefs`), and made the plain cursor, its
window, the misses, and the shared aggregate move only what an edit touched
(`model/subscription/cover.rs`). `publisher_update` measures it. What
remains:

- Rust, a relay's front (`rs/moq-net/src/model/resume.rs`): `Reader::sync`
materializes the whole `Subscription` on each change, rebuilds the reader's
window, and hands every copy a whole `update`, whose own cursor then
rebuilds. The demand fold (`poll_combined`) materializes each reader's
preferences too. Replay `Prefs::changes` into the reader's window and pass
each copy the edit, clamped per copy, through `track::Subscriber::edit`; the
copy's positional `resolved_ranges` and `Copy::from` become keyed. Add a
routed case to `publisher_update`.
- Rust, the servable index (`model/track.rs` `Live`): rebuilt from the cache
arrivals whenever the groups' cover moves, so an edit costs the cache held,
not the ranges.
- JS: `combineSubscriptions` in `js/net/src/track.ts` rebuilds the union over
every subscriber on each `Subscriber.update`, so a preference-only update
costs the whole audience there; give it the incremental union
`rs/moq-net/src/model/track/demand/ranges.rs` keeps.

Recommended: key the model's ranges and their resolutions by an id the
caller assigns, so a publisher passes the edit straight through, and measure
an update stream against a 16k-range subscription before and after.
every subscriber on each `Subscriber.update`; give it the incremental union
`rs/moq-net/src/model/track/demand/ranges.rs` keeps, and mirror the Rust
edit path in `js/net/src/lite/publisher.ts` and `lite/subscribe.ts`.

The rework is internal-only: no public API changes in `moq-net`, `moq-ffi`, or
`@moq/net` (checked when the range union fix landed, the condition for leaving
this to m2). Keep it that way:
`@moq/net`. Keep it that way:

- Rust: add a crate-private edit entry point on `track::Subscriber` (retired
ids, added `(id, Range)` pairs, and the preferences) beside the public
`update(Subscription)`. The per-subscriber ranges and the window's
resolutions become keyed; `Window` is `pub(in crate::model)`, and
`Resolved`, `resolved()`, and `Preferences` are crate-private already. The
public `update` stays a whole-set replacement, costing what its caller
passes, and `subscription()` keeps returning ranges in the order last given.
`Subscription`, `Range`, and the aggregate getters keep their shapes.
- Rust: the edit entry point stays crate-private; the public `update` stays a
whole-set replacement and `subscription()` keeps returning ranges in the
order last given.
- JS: reach the edit through an internal `hooks.*` accessor, as the lite
publisher already does for the track, and keep the per-producer union
incremental behind the existing `Subscription` signal. `Subscriber.update`
Expand Down
35 changes: 33 additions & 2 deletions rs/moq-net/benches/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
//! up as a slope over `skipped`. `adjacent` gives up the groups of one range instead, each
//! with a different error from its neighbor, so the record holds one entry per group.
//!
//! `publisher_update` feeds a lite-07 subscription of `ranges` one-group ranges a stream of
//! SUBSCRIBE_UPDATEs, each retiring the `edited` oldest ranges and adding as many, then serving
//! until parked; `steer` moves only the priority. A cost that grows with the live ranges
//! rather than the edit shows up as a slope over `ranges`.
//!
//! Run with `cargo bench -p moq-net --features fuzz --bench publisher`.

use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
use moq_net::fuzz::CoverageBench;
use moq_net::fuzz::{CoverageBench, UpdateBench};

/// Ranges the source gave up before the wake.
const SKIPPED: [u64; 4] = [1, 32, 1024, 8192];
Expand Down Expand Up @@ -38,5 +43,31 @@ fn bench_covered_before_start(c: &mut Criterion) {
group.finish();
}

criterion_group!(benches, bench_covered_before_start);
/// Live ranges in the subscription, up to about the most one-group ranges a SUBSCRIBE fits.
const LIVE: [u64; 3] = [16, 512, 8192];

/// Ranges each update retires, and adds.
const EDITED: [u64; 2] = [1, 16];

fn bench_update(c: &mut Criterion) {
let mut group = c.benchmark_group("publisher_update");
group.throughput(Throughput::Elements(1));
for ranges in LIVE {
for edited in EDITED {
let mut run = None;
group.bench_function(BenchmarkId::new(format!("edit{edited}"), ranges), |b| {
let run = run.get_or_insert_with(|| UpdateBench::new(ranges));
b.iter(|| run.edit(edited));
});
}
let mut run = None;
group.bench_function(BenchmarkId::new("steer", ranges), |b| {
let run = run.get_or_insert_with(|| UpdateBench::new(ranges));
b.iter(|| run.steer());
});
}
group.finish();
}

criterion_group!(benches, bench_covered_before_start, bench_update);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion rs/moq-net/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub use request::request;
pub use session::{session_ietf, session_lite};

/// Lite-07 publisher run loops for the publisher bench.
pub use crate::lite::CoverageBench;
pub use crate::lite::{CoverageBench, UpdateBench};

use bytes::Bytes;

Expand Down
2 changes: 1 addition & 1 deletion rs/moq-net/src/lite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod probe;
#[cfg(feature = "async")]
mod publisher;
#[cfg(all(feature = "async", any(test, feature = "fuzz")))]
pub use publisher::CoverageBench;
pub use publisher::{CoverageBench, UpdateBench};
#[cfg(feature = "async")]
mod replay;
#[cfg(feature = "async")]
Expand Down
Loading