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
28 changes: 23 additions & 5 deletions bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ extra copy of every received stream chunk injected into `@moq/net`, the control
that shows the suite can see a copy-heavy change), and `base` when a revision is
given. Each variant resolves `@moq/*` from its own checkout. Variants alternate
within each round, with the starting variant rotated, after one warmup round
(`--rounds`, `--warmup`, `--scenarios transport,cmaf,media,racing`).
(`--rounds`, `--warmup`, `--scenarios transport,cmaf,media,racing,stats`).

- `transport`: a publisher page writes 160 B through 1 MiB frames, a consumer page
subscribes and reads them all. Connection setup and fixture generation stay
Expand Down Expand Up @@ -437,6 +437,19 @@ within each round, with the starting variant rotated, after one warmup round
collection, a heap snapshot counts the flat strings still holding the run's URL
marker, with their V8 object bytes and characters. A forced arm's winner is
checked; an open race's is only reported.
- `stats`: one page holds `Moq.Connection` handles open while they do nothing
else, to measure local send-rate sampling. Distinct reconnect loops (1, 4, 16)
cross reservations held on each (0, 1, 4); receive-only playback of a 30 fps
track, pooled connections inside the linger window after their last handle
closed, four identical pooled handles (one connection, the control) and qmux
complete the sweep. After a settle, a 2 s window (1.2 s for linger) reports
`getStats` calls and `setTimeout` calls per second, main-thread and process
CPU, and how many reservations hold a send-rate slice. `stats resume` releases
and re-takes a reservation ten times, 500 ms apart, timing its first slice.
Shipping Chromium has no `WebTransport.getStats()`, so this scenario runs in a
second browser with `--enable-blink-features=WebTransportStats`; its `absent`
shapes delete the method again, as shipping Chromium and Safari present it. The
`copy` control does not run here: nothing receives stream chunks in bulk.

Costs are split by where they run. Main-thread CPU is CDP `TaskDuration` in
thread ticks; process CPU is each page's renderer (every thread, including
Expand All @@ -446,8 +459,10 @@ keep instrumentation out of timed samples: a traced pass retains a gzipped Chrom
trace per workload and reports GC pauses and reclaimed JS heap; a counted pass
wraps typed-array constructors, `set` and `slice` to report JS-visible bytes
copied and allocated per payload byte during delivery, with connection setup
subtracted; a probed pass reads each presented
frame's painted id back to report frame delay percentiles. Native copies inside
subtracted (for `stats`, V8's sampling heap profiler reports every byte the
window allocated, collected or not); a probed pass reads each presented
frame's painted id back to report frame delay percentiles. The `stats` call
counters are one increment per call and run in every pass. Native copies inside
WebTransport and WebCodecs are unavailable, and the report says so.

Chromium runs headless with `--disable-gpu`, so decode and rendering are
Expand All @@ -472,8 +487,11 @@ order-independent digest must match, so skipped work cannot read as a speedup.
CMAF output is decoded and checked byte for byte in a separate call after each
phase's CPU and trace snapshots.
Crashes, wrong bytes, missing frames, a window that presents nothing, a racing
dial that fails or a forced racing arm won by the other transport, or an
unavailable CPU clock fail the run; timing never does. The nightly runs
dial that fails or a forced racing arm won by the other transport, a stats
window whose reservations hold more or fewer send-rate slices than the transport
can give (every one over WebTransport with `getStats()`, none over qmux or
without it), a resume cycle that never gets its slice, or an unavailable CPU
clock fail the run; timing never does. The nightly runs
`--smoke`, whose racing sweep runs every mode and a rotated query at 4 URLs x 2
reconnects x 64 characters, and keeps its run directory as the `bench-browser`
artifact.
Expand Down
4 changes: 3 additions & 1 deletion bench/browser/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { basename, join, resolve } from "node:path";
import type { BunPlugin } from "bun";
import { workspace } from "./workspace.ts";

const PAGES = ["transport", "cmaf", "media", "racing"].map((page) => join(import.meta.dir, "page", `${page}.ts`));
const PAGES = ["transport", "cmaf", "media", "racing", "stats"].map((page) =>
join(import.meta.dir, "page", `${page}.ts`),
);

// The one statement every received byte passes through; the control copies it.
const CHUNK = "this.#chunks.push(result.value);";
Expand Down
39 changes: 39 additions & 0 deletions bench/browser/calls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Init scripts for the sampling scenario, installed before any page module runs.
*
* Each function is serialized into the page, so it must not close over anything.
*/

/**
* Counts `WebTransport.getStats` calls and every `setTimeout`, the primitive behind
* `@moq/clock` sleeps, on `globalThis.__sampling`. One increment per call, in every pass and
* every variant. The page patches `@moq/qmux`'s `getStats` into the same counter.
*/
export function install(): void {
const counts = { getstats: 0, timers: 0 };
Object.defineProperty(globalThis, "__sampling", { value: counts });
const timeout = globalThis.setTimeout;
globalThis.setTimeout = ((handler: TimerHandler, delay?: number, ...args: unknown[]) => {
counts.timers++;
return timeout(handler, delay, ...args);
}) as typeof setTimeout;
const transport = (globalThis as { WebTransport?: { prototype: { getStats?: () => Promise<unknown> } } })
.WebTransport?.prototype;
const getStats = transport?.getStats;
if (transport && getStats)
transport.getStats = function (this: unknown) {
counts.getstats++;
return getStats.call(this);
};
}

/** Removes WebTransport, as in a browser lacking it, so every dial takes the qmux fallback. */
export function withoutWebTransport(): void {
Object.defineProperty(globalThis, "WebTransport", { value: undefined, configurable: true, writable: true });
}

/** Deletes WebTransport getStats(), which shipping Chromium and Safari do not expose. */
export function withoutGetStats(): void {
const transport = (globalThis as { WebTransport?: { prototype: { getStats?: unknown } } }).WebTransport;
if (transport) delete transport.prototype.getStats;
}
Loading
Loading