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/performance-survey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ No duplicate quest or workflow edit belongs here.
- [Cached JS group joins](/quest/m2/performance-survey/js-cached-groups.md) - repeated sorting while replaying retained groups
- [PCM batch processing](/quest/m2/performance-survey/audio-batches.md) - repeated tail movement during encoding and resampling
- [Fragmented MKV import](/quest/m2/performance-survey/mkv-fragments.md) - accumulated-buffer copies and parser replay
- [QUIC scheduling churn](/quest/m2/performance-survey/quic-schedule-churn.md) - priority and retirement work across unrelated groups
- [HLS request fan-out](/quest/m2/performance-survey/hls-serving.md) - repeated fetch, remux and playlist construction per viewer
- [Buffered browser groups](/quest/m2/performance-survey/hang-buffered.md) - per-frame scans and bulk skip work
- [Idle browser stats](/quest/m2/performance-survey/browser-idle-stats.md) - local transport polling without active publishing demand
Expand Down
30 changes: 0 additions & 30 deletions quest/m2/performance-survey/quic-schedule-churn.md

This file was deleted.

119 changes: 117 additions & 2 deletions rs/moq-quic/benches/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! finish them, then exchange packets until the server has read them and the path is idle.
//! The zero-credit case isolates blocked writes and resets across live-writer counts, with
//! connection setup and dropping the remaining state outside the CPU measurement. The
//! reprioritize case moves streams that stay queued, never sending them.
//! reprioritize case moves streams that stay queued, never sending them. The group churn case
//! moves and cancels send groups, one per subscription, while the rest have data queued.

use bytes::Bytes;
use criterion::{BatchSize, BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
Expand Down Expand Up @@ -65,6 +66,57 @@ fn bench_schedule(c: &mut Criterion<ThreadCpu>) {
);
}
}

// Moving or retiring some queued groups, as subscription updates and cancels do, while the
// rest stay queued. Groups are picked from the front of the round robin, its tail, or spread
// across it, so a cost that grows with the untouched groups shows as a slope.
let queued_groups = |groups: usize| {
let mut schedule = Schedule::<usize, ()>::new();
let ids: Vec<_> = (0..groups).map(|_| schedule.open_group(0)).collect();
let mut slots: Vec<_> = (0..groups).map(|_| Slot::default()).collect();
for (id, slot) in slots.iter_mut().enumerate() {
schedule.join(id, slot, Some(ids[id]), 0);
schedule.push(id, slot, 0);
}
(schedule, ids, slots)
};
for (queued, changed) in [(16, 16), (256, 16), (4096, 16), (4096, 256)] {
for order in ["front", "tail", "mixed"] {
let picked: Vec<usize> = match order {
"front" => (0..changed).collect(),
"tail" => (queued - changed..queued).rev().collect(),
// An odd stride visits distinct groups of a power-of-two count.
_ => (0..changed).map(|i| i * 2_654_435_761 % queued).collect(),
};
let id = format!("queued_{queued}_changed_{changed}_{order}");
group.throughput(Throughput::Elements(changed as u64));
group.bench_function(BenchmarkId::new("group_priority", &id), |b| {
b.iter_batched(
|| queued_groups(queued),
|(mut schedule, ids, slots)| {
for &index in &picked {
schedule.set_group_priority(ids[index], 1);
}
(schedule, slots)
},
BatchSize::LargeInput,
)
});
group.bench_function(BenchmarkId::new("group_retire", &id), |b| {
b.iter_batched(
|| queued_groups(queued),
|(mut schedule, ids, mut slots)| {
for &index in &picked {
schedule.close_group(ids[index]);
schedule.leave(&mut slots[index]);
}
(schedule, slots)
},
BatchSize::LargeInput,
)
});
}
}
group.finish();
}

Expand Down Expand Up @@ -143,6 +195,69 @@ fn bench_reprioritize(c: &mut Criterion<ThreadCpu>) {
group.finish();
}

/// Subscription churn on a shared connection: each round writes one small stream in each of
/// `subs` send groups, then, with all of it queued, moves `churn` groups spread across the
/// round robin to another priority and back and cancels `churn` others (reset the stream,
/// close the group, open its replacement), and drives until the server has seen every stream.
fn bench_group_churn(c: &mut Criterion<ThreadCpu>) {
use moq_quic::send;
const BYTES: usize = 256;
let data = payload(BYTES);
let mut group = c.benchmark_group("group_churn");
for (subs, churn) in [(16_usize, 4), (256, 16), (4096, 16), (4096, 256)] {
// The moved and cancelled groups stay distinct, below.
assert!(2 * churn <= subs && subs.is_power_of_two());
let mut pair = Pair::new(Setup::default());
let mut groups: Vec<_> = (0..subs).map(|_| pair.client().send_groups().open(0)).collect();
let mut round = 0;
group.throughput(Throughput::Elements(subs as u64));
group.bench_function(
BenchmarkId::new(format!("subs_{subs}"), format!("churn_{churn}")),
|b| {
b.iter(|| {
round += 1;
let finished = pair.server.received.finished;
let reset = pair.server.received.reset;
let conn = pair.client();
let ids: Vec<_> = groups
.iter()
.map(|group| {
let options = send::Options {
group: Some(group),
priority: 0,
};
let id = conn.streams().open(Dir::Uni, options).expect("stream limit");
let mut stream = conn.send_stream(id);
assert_eq!(stream.write(&mut data.clone()).unwrap(), BYTES);
stream.finish().unwrap();
id
})
.collect();
// An odd stride permutes a power-of-two count, spreading the touched groups over
// the round robin and shifting them each round.
let spread = |i: usize| (round + i * 2_654_435_761) % subs;
for index in (0..churn).map(spread) {
conn.send_groups().set_priority(&groups[index], 1);
conn.send_groups().set_priority(&groups[index], 0);
}
for index in (churn..2 * churn).map(spread) {
conn.send_stream(ids[index]).reset(0u32.into()).unwrap();
let fresh = conn.send_groups().open(0);
conn.send_groups().close(std::mem::replace(&mut groups[index], fresh));
}
let target = (finished + (subs - churn) as u64, reset + churn as u64);
pair.drive_until(|pair| {
let received = &pair.server.received;
received.finished >= target.0 && received.reset >= target.1
});
pair.settle();
})
},
);
}
group.finish();
}

/// Writes `total` bytes to one stream in `size`-byte writes, exchanging packets whenever the
/// client's send window is full, and drives until the server has read them all.
fn send_windowed(pair: &mut Pair, total: usize, size: usize) {
Expand Down Expand Up @@ -296,6 +411,6 @@ fn bench_probe(c: &mut Criterion<ThreadCpu>) {
criterion_group! {
name = benches;
config = common::config();
targets = bench_schedule, bench_priority, bench_reprioritize, bench_write_size, bench_connection_blocked, bench_probe
targets = bench_schedule, bench_priority, bench_reprioritize, bench_group_churn, bench_write_size, bench_connection_blocked, bench_probe
}
criterion_main!(benches);
Loading