Skip to content

armgit / Piik

Public Imported from GitHub
0

Free, open-source screen sharing for private live streams with friends. Watch together in a browser or self-host Piik. 免费开源的私密屏幕共享,支持游戏直播、一起看电影与自部署。

test(benchmark): record relay resource evidence (#172)

AAA92c53bdd5f48
diff --git a/docs/research/peer-assisted-media.md b/docs/research/peer-assisted-media.md
index f4c01346..60c11301 100644
--- a/docs/research/peer-assisted-media.md
+++ b/docs/research/peer-assisted-media.md
@@ -272,6 +272,14 @@ captured. This proves the explicit admission, bounded topology, and decode paths
only; resource, visual quality, endurance, heterogeneous networks, and the
separate 20-viewer gate remain open.
+A same-machine 2026-08-22 Chrome 151 follow-up ran sixteen Viewers for ten seconds at 720p30 and introduced report schema v2; sender means are unweighted connected sender-sample means, while encode cost is weighted by guarded interval frame deltas.
+Cap2 passed at Host2/relay2 with 2 Host and 14 relay senders: Host/relay bitrate was 1,716/1,748 kbps, FPS 11.17/11.20, available outgoing 5,393/5,704 kbps, and encode cost 2.086/2.048 ms per frame.
+Cap3 passed at Host3/relay3 with 3 Host and 13 relay senders: the same fields were 1,589/1,638 kbps, 10.83/10.87 FPS, 5,474/5,956 kbps, and 2.071/2.126 ms per frame.
+Both runs observed only 320x180 and 480x270; every Host limitation sample was `bandwidth`, every relay sample was `none`, and maximum first-decode diagnostics were 1,071/1,021 ms for cap2/cap3.
+[CDP `SystemInfo.getProcessInfo`](https://chromedevtools.github.io/devtools-protocol/tot/SystemInfo/) exposes process type, PID, and cumulative CPU seconds, but no resident-set field; v2 therefore reports peak RSS as `null` and rejects intervals when the exact type/PID set changes or any counter retreats.
+Cap2 measured 221.4% aggregate Chromium CPU (250.7% peak) over two valid and three rejected intervals; cap3 measured 209.8% (246.9% peak) over four valid and one rejected interval. Multicore totals may exceed 100%.
+The different valid coverage and one short run per arm forbid a cap2/cap3 CPU ranking. CDP cannot attribute these all-process totals to an individual Host or relay page, and this ordinary-PC synthetic run does not close the resource, game-quality, endurance, mobile, or 20-viewer gates.
+
Peer multicast research such as SplitStream demonstrates why load-balanced,
failure-tolerant overlays normally introduce multiple trees and content
striping. Those mechanisms are intentionally excluded: needing them is a reason
diff --git a/scripts/peer-assisted-benchmark.ts b/scripts/peer-assisted-benchmark.ts
index 5e35dd65..ccc9c833 100644
--- a/scripts/peer-assisted-benchmark.ts
+++ b/scripts/peer-assisted-benchmark.ts
@@ -102,8 +102,11 @@ interface TimedSample {
atEpochMs: number;
elapsedMs: number;
pages: PageObservation[];
+ browserProcesses?: BrowserProcessSample | null;
}
+interface BrowserProcessSample { processes: Array<{ type: string; id: number; cpuTimeSeconds: number }> }
+
interface RunCheck {
name: string;
passed: boolean;
@@ -153,7 +156,7 @@ interface BenchmarkRun {
}
interface BenchmarkReport {
- schemaVersion: 1;
+ schemaVersion: 2;
startedAt: string;
completedAt: string | null;
gitCommit: string | null;
@@ -679,6 +682,12 @@ export function summarizeSamples(samples: TimedSample[], viewerCount: number) {
firstFrames,
maxFirstDecodedAfterAuthenticateMs:
decodedDelays.length === viewerCount ? Math.max(...decodedDelays) : null,
+ senderEvidence: {
+ scope: "connected outbound video with stable page, connection, and RTP identities",
+ host: summarizeSenderEvidence(samples, "host"),
+ relay: summarizeSenderEvidence(samples, "viewer"),
+ },
+ browserProcessResources: summarizeBrowserProcessResources(samples),
finalTopology: finalPages.map((page) => ({
label: page.label,
role: page.role,
@@ -715,6 +724,122 @@ export function summarizeSamples(samples: TimedSample[], viewerCount: number) {
};
}
+function numericSummary(values: number[]) {
+ return {
+ sampleCount: values.length,
+ min: values.length > 0 ? Math.min(...values) : null,
+ max: values.length > 0 ? Math.max(...values) : null,
+ mean: values.length > 0
+ ? values.reduce((total, value) => total + value, 0) / values.length
+ : null,
+ };
+}
+
+function summarizeSenderEvidence(samples: TimedSample[], role: PageRole) {
+ const identities = new Set<string>();
+ const bitrateKbps: number[] = [], framesPerSecond: number[] = [];
+ const availableOutgoingKbps: number[] = [];
+ const resolutions = new Set<string>();
+ const qualityLimitationReasonSamples: Record<string, number> = {};
+ let unknownIdentitySamples = 0;
+ let unknownQualityLimitationSamples = 0;
+ let encodeIntervalCount = 0, framesEncoded = 0, encodeTimeMs = 0;
+ const finite = (value: unknown): value is number =>
+ typeof value === "number" && Number.isFinite(value);
+
+ for (const sample of samples) {
+ for (const page of sample.pages.filter((candidate) => candidate.role === role)) {
+ for (const connection of page.connections) {
+ if (!connection.hasOutboundVideo || connection.connectionState !== "connected" || !connection.send) continue;
+ const rtpStatsId = connection.send.rtpStatsId;
+ if (typeof rtpStatsId !== "string" || rtpStatsId.length === 0) {
+ unknownIdentitySamples += 1;
+ continue;
+ }
+ identities.add(`${page.label}:${connection.createdAtEpochMs}:${connection.connectionId ?? connection.index}:${rtpStatsId}`);
+ if (finite(connection.send.bitrateKbps)) bitrateKbps.push(connection.send.bitrateKbps);
+ if (finite(connection.send.framesPerSecond)) framesPerSecond.push(connection.send.framesPerSecond);
+ if (finite(connection.send.availableOutgoingKbps)) availableOutgoingKbps.push(connection.send.availableOutgoingKbps);
+ if (typeof connection.send.resolution === "string" && /^\d+x\d+$/.test(connection.send.resolution)) resolutions.add(connection.send.resolution);
+ const reason = connection.send.qualityLimitationReason;
+ if (typeof reason === "string" && reason.length > 0) {
+ qualityLimitationReasonSamples[reason] = (qualityLimitationReasonSamples[reason] ?? 0) + 1;
+ } else {
+ unknownQualityLimitationSamples += 1;
+ }
+ const intervalFrames = connection.send.intervalFramesEncoded;
+ const intervalTime = connection.send.intervalEncodeTimeMs;
+ if (finite(intervalFrames) && intervalFrames >= 0 && finite(intervalTime) && intervalTime >= 0) {
+ encodeIntervalCount += 1;
+ framesEncoded += intervalFrames;
+ encodeTimeMs += intervalTime;
+ }
+ }
+ }
+ }
+ return {
+ uniqueSenderCount: identities.size,
+ unknownIdentitySamples,
+ bitrateKbps: numericSummary(bitrateKbps),
+ framesPerSecond: numericSummary(framesPerSecond),
+ resolutions: resolutions.size > 0 ? [...resolutions].sort() : null,
+ availableOutgoingKbps: numericSummary(availableOutgoingKbps),
+ encodeIntervals: {
+ sampleCount: encodeIntervalCount,
+ framesEncoded: encodeIntervalCount > 0 ? framesEncoded : null,
+ encodeTimeMs: encodeIntervalCount > 0 ? encodeTimeMs : null,
+ meanEncodeMsPerFrame: framesEncoded > 0 ? encodeTimeMs / framesEncoded : null,
+ },
+ qualityLimitationReasonSamples: Object.keys(qualityLimitationReasonSamples).length > 0
+ ? qualityLimitationReasonSamples : null,
+ unknownQualityLimitationSamples,
+ };
+}
+
+function summarizeBrowserProcessResources(samples: TimedSample[]) {
+ let validCpuIntervals = 0, invalidCpuIntervals = 0;
+ let measuredCpuTimeSeconds = 0, measuredWallTimeSeconds = 0;
+ let peakIntervalCpuUtilizationPercent: number | null = null;
+ for (let index = 1; index < samples.length; index += 1) {
+ const previous = samples[index - 1]!;
+ const current = samples[index]!;
+ const wallSeconds = (current.atEpochMs - previous.atEpochMs) / 1_000;
+ const previousProcesses = previous.browserProcesses?.processes;
+ const currentProcesses = current.browserProcesses?.processes;
+ const previousByIdentity = new Map(previousProcesses?.map((process) => [`${process.type}:${process.id}`, process]));
+ let cpuSeconds = 0;
+ const valid = wallSeconds > 0 && previousProcesses && currentProcesses &&
+ previousProcesses.length === currentProcesses.length && previousByIdentity.size === previousProcesses.length &&
+ currentProcesses.every((process) => {
+ const baseline = previousByIdentity.get(`${process.type}:${process.id}`);
+ if (!baseline || process.cpuTimeSeconds < baseline.cpuTimeSeconds) return false;
+ cpuSeconds += process.cpuTimeSeconds - baseline.cpuTimeSeconds;
+ return true;
+ });
+ if (!valid) {
+ invalidCpuIntervals += 1;
+ continue;
+ }
+ validCpuIntervals += 1;
+ measuredCpuTimeSeconds += cpuSeconds;
+ measuredWallTimeSeconds += wallSeconds;
+ const utilization = (cpuSeconds / wallSeconds) * 100;
+ peakIntervalCpuUtilizationPercent = Math.max(peakIntervalCpuUtilizationPercent ?? 0, utilization);
+ }
+ return {
+ source: "CDP SystemInfo.getProcessInfo",
+ scope: "all CDP-reported processes in the isolated benchmark Chromium instance",
+ validCpuIntervals,
+ invalidCpuIntervals,
+ measuredCpuTimeSeconds: validCpuIntervals ? measuredCpuTimeSeconds : null,
+ measuredWallTimeSeconds: validCpuIntervals ? measuredWallTimeSeconds : null,
+ averageCpuUtilizationPercent: measuredWallTimeSeconds > 0
+ ? (measuredCpuTimeSeconds / measuredWallTimeSeconds) * 100 : null,
+ peakIntervalCpuUtilizationPercent,
+ peakResidentSetBytes: null,
+ };
+}
+
export function buildRunChecks(
summary: NonNullable<BenchmarkRun["summary"]>,
viewerCount: number,
@@ -1595,14 +1720,39 @@ async function samplePages(
startedAtMs: number,
): Promise<TimedSample> {
const atEpochMs = Date.now();
- const observations = await Promise.all(pages.map((page) => detailedSample(cdp, page)));
+ const [observations, browserProcesses] = await Promise.all([
+ Promise.all(pages.map((page) => detailedSample(cdp, page))),
+ sampleBrowserProcesses(cdp),
+ ]);
return {
atEpochMs,
elapsedMs: atEpochMs - startedAtMs,
pages: observations,
+ browserProcesses,
};
}
+async function sampleBrowserProcesses(cdp: CdpConnection): Promise<BrowserProcessSample | null> {
+ try {
+ const result = await cdp.call<{ processInfo: unknown[] }>("SystemInfo.getProcessInfo");
+ if (!Array.isArray(result.processInfo)) return null;
+ const processes: BrowserProcessSample["processes"] = [];
+ const identities = new Set<string>();
+ for (const raw of result.processInfo) {
+ if (!raw || typeof raw !== "object") return null;
+ const { type, id, cpuTime } = raw as Record<string, unknown>;
+ if (typeof type !== "string" || type.length === 0 || !Number.isSafeInteger(id) || Number(id) < 0 || typeof cpuTime !== "number" || !Number.isFinite(cpuTime) || cpuTime < 0) return null;
+ const identity = `${type}:${id}`;
+ if (identities.has(identity)) return null;
+ identities.add(identity);
+ processes.push({ type, id: Number(id), cpuTimeSeconds: cpuTime });
+ }
+ return { processes: processes.sort((left, right) => left.id - right.id || left.type.localeCompare(right.type)) };
+ } catch {
+ return null;
+ }
+}
+
function peerConnectionFingerprint(pages: PageObservation[]): string {
return pages
.map((page) =>
@@ -2249,7 +2399,7 @@ export async function main(): Promise<number> {
const profile = PROFILE_SETTINGS[config.profileId];
const profileResolution = QUALITY_RESOLUTIONS[profile.resolution];
const report: BenchmarkReport = {
- schemaVersion: 1,
+ schemaVersion: 2,
startedAt: new Date().toISOString(),
completedAt: null,
gitCommit: await gitCommit(),
@@ -2287,7 +2437,8 @@ export async function main(): Promise<number> {
"Synthetic canvas motion exercises real Chromium WebRTC but is not a game-capture quality claim.",
"Headless runs are topology and transport evidence, not representative GPU or power evidence.",
"First-frame and recovery timing fields are diagnostics and never determine this loopback gate's status.",
- "CPU, GPU, NIC totals, glass-to-glass latency, generational visual quality, mobile browsers, and TURN require external or device-specific measurement.",
+ "CDP process CPU covers the isolated Chromium instance, not a specific Host or relay page; identity changes or counter resets make that interval unknown, and multicore utilization may exceed 100%.",
+ "CDP SystemInfo exposes no resident-set field, so peakResidentSetBytes is null; GPU, NIC, glass-to-glass latency, generational visual quality, mobile browsers, and TURN require other measurement.",
"The local runner does not start LiveKit; SFU consistency is reported only when an SFU route is actually observed.",
"The harness emits raw gate fields and simple invariants; it does not implement a route score or runtime policy.",
],
diff --git a/tests/peer-assisted-benchmark.test.ts b/tests/peer-assisted-benchmark.test.ts
index a8d8b989..a73b6611 100644
--- a/tests/peer-assisted-benchmark.test.ts
+++ b/tests/peer-assisted-benchmark.test.ts
@@ -308,6 +308,8 @@ describe("peer topology loopback observations", () => {
expect(summary.everyViewerDecoded).toBe(true);
expect(summary.firstFrames[0]?.decodedAfterAuthenticateMs).toBe(600);
expect(summary.maxFirstDecodedAfterAuthenticateMs).toBe(600);
+ expect(summary.senderEvidence.host.bitrateKbps.mean).toBeNull();
+ expect(summary.browserProcessResources.measuredCpuTimeSeconds).toBeNull();
expect(
summary.finalTopology.every(
(entry) =>
@@ -317,6 +319,59 @@ describe("peer topology loopback observations", () => {
).toBe(true);
});
+ it("summarizes identified sender evidence and rejects reset process intervals", () => {
+ const makePages = (bitrate: number, fps: number, intervalFrames: number | null, intervalTime: number | null, reason: string) => {
+ const pages = [page("host", "host", 1, 0), page("viewer", "viewer-1", 1, 1)];
+ pages[0]!.connections[0]!.send = {
+ rtpStatsId: "host-rtp",
+ bitrateKbps: bitrate,
+ framesPerSecond: fps,
+ resolution: fps === 25 ? "640x360" : "1280x720",
+ availableOutgoingKbps: bitrate * 4,
+ intervalFramesEncoded: intervalFrames,
+ intervalEncodeTimeMs: intervalTime,
+ qualityLimitationReason: reason,
+ };
+ pages[1]!.connections[0]!.send = {
+ ...pages[0]!.connections[0]!.send,
+ rtpStatsId: "relay-rtp",
+ bitrateKbps: bitrate / 2,
+ };
+ return pages;
+ };
+ const processSample = (browserCpu: number, rendererCpu: number) => ({ processes: [
+ { type: "browser", id: 1, cpuTimeSeconds: browserCpu }, { type: "renderer", id: 2, cpuTimeSeconds: rendererCpu },
+ ] });
+ const summary = summarizeSamples(
+ [
+ { atEpochMs: 2_000, elapsedMs: 0, pages: makePages(1_000, 25, null, null, "none"), browserProcesses: processSample(10, 2) },
+ { atEpochMs: 4_000, elapsedMs: 2_000, pages: makePages(1_200, 30, 20, 40, "none"), browserProcesses: processSample(10.4, 2.6) },
+ { atEpochMs: 6_000, elapsedMs: 4_000, pages: makePages(1_400, 30, 30, 75, "cpu"), browserProcesses: processSample(9, 3) },
+ ],
+ 1,
+ );
+
+ expect(summary.senderEvidence.host).toMatchObject({
+ uniqueSenderCount: 1,
+ unknownIdentitySamples: 0,
+ bitrateKbps: { sampleCount: 3, min: 1_000, max: 1_400, mean: 1_200 },
+ framesPerSecond: { sampleCount: 3, min: 25, max: 30 },
+ resolutions: ["1280x720", "640x360"],
+ encodeIntervals: { sampleCount: 2, framesEncoded: 50, encodeTimeMs: 115 },
+ qualityLimitationReasonSamples: { none: 2, cpu: 1 },
+ });
+ expect(summary.senderEvidence.host.encodeIntervals.meanEncodeMsPerFrame).toBe(2.3);
+ expect(summary.senderEvidence.relay.bitrateKbps.mean).toBe(600);
+ expect(summary.browserProcessResources).toMatchObject({
+ validCpuIntervals: 1,
+ invalidCpuIntervals: 1,
+ measuredWallTimeSeconds: 2,
+ peakResidentSetBytes: null,
+ });
+ expect(summary.browserProcessResources.measuredCpuTimeSeconds).toBeCloseTo(1);
+ expect(summary.browserProcessResources.averageCpuUtilizationPercent).toBeCloseTo(50);
+ });
+
it("requires an explicit cap3 run to exercise cap3 fanout", () => {
const initial = [
page("host", "host", 3, 0),