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
52 changes: 52 additions & 0 deletions packages/producer/src/services/distributed/renderChunk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
PLAN_HASH_MISMATCH,
renderChunk,
RenderChunkValidationError,
chunkCaptureSizingLog,
resolveChunkCaptureWorkers,
resolveLockedVp9CpuUsed,
resolvePresetForLockedEncoder,
Expand Down Expand Up @@ -1118,6 +1119,57 @@ describe("interleavesCapture", () => {
});
});

describe("chunkCaptureSizingLog", () => {
const machineSizing = {
workers: 3,
boundBy: "memory" as const,
cpuBasedWorkers: 6,
memoryBasedWorkers: 3,
frameBasedWorkers: 8,
};

it("names the worker count, what bound it, and the wall time per frame", () => {
expect(
chunkCaptureSizingLog({
chunkIndex: 2,
framesEncoded: 240,
workers: 5,
machineSizing,
maxCaptureWorkers: 5,
captureMode: "beginframe",
captureStageMs: 18_750,
}),
).toEqual({
chunkIndex: 2,
frames: 240,
workers: 5,
machineSizedWorkers: 3,
boundBy: "memory",
cpuBasedWorkers: 6,
memoryBasedWorkers: 3,
frameBasedWorkers: 8,
maxCaptureWorkers: 5,
captureMode: "beginframe",
captureStageMs: 18_750,
captureMsPerFrame: 78.1,
});
});

it("reports no per-frame time for a chunk that encoded no frame", () => {
const line = chunkCaptureSizingLog({
chunkIndex: 0,
framesEncoded: 0,
workers: 1,
machineSizing,
maxCaptureWorkers: undefined,
captureMode: "screenshot",
captureStageMs: 12,
});
expect(line.captureMsPerFrame).toBeNull();
expect(line.maxCaptureWorkers).toBeNull();
});
});

describe("resolveChunkCaptureWorkers", () => {
it("keeps the machine-wide sizing when the runtime sets no budget", () => {
expect(resolveChunkCaptureWorkers(121, 3, undefined)).toBe(3);
Expand Down
51 changes: 49 additions & 2 deletions packages/producer/src/services/distributed/renderChunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ import { join } from "node:path";
import {
assertSwiftShader,
BROWSER_GPU_NOT_SOFTWARE,
calculateOptimalWorkers,
classifyCaptureFailure,
computeWorkerSizing,
type CaptureOptions,
type CaptureMode,
type CapturePerfSummary,
type CaptureSession,
type WorkerSizing,
closeCaptureSession,
createCaptureSession,
createFrameLookupTable,
Expand Down Expand Up @@ -248,6 +249,39 @@ export function resolveChunkCaptureWorkers(
return Math.max(machineSized, Math.floor(Math.min(maxCaptureWorkers, byFrames)));
}

/** One chunk's capture in a line: how many browsers it ran and why, and what a frame cost in wall time. */
export function chunkCaptureSizingLog(input: {
chunkIndex: number;
framesEncoded: number;
workers: number;
machineSizing: Pick<
WorkerSizing,
"workers" | "boundBy" | "cpuBasedWorkers" | "memoryBasedWorkers" | "frameBasedWorkers"
>;
maxCaptureWorkers: number | undefined;
captureMode: CaptureMode;
captureStageMs: number;
}): Record<string, string | number | null> {
const { machineSizing } = input;
return {
chunkIndex: input.chunkIndex,
frames: input.framesEncoded,
workers: input.workers,
machineSizedWorkers: machineSizing.workers,
boundBy: machineSizing.boundBy,
cpuBasedWorkers: machineSizing.cpuBasedWorkers,
memoryBasedWorkers: machineSizing.memoryBasedWorkers,
frameBasedWorkers: machineSizing.frameBasedWorkers,
maxCaptureWorkers: input.maxCaptureWorkers ?? null,
captureMode: input.captureMode,
captureStageMs: input.captureStageMs,
captureMsPerFrame:
input.framesEncoded > 0
? Math.round((input.captureStageMs / input.framesEncoded) * 10) / 10
: null,
};
}

/** The frames a chunk renders: its slice, or a validated sub-range of it. */
export function resolveChunkFrameRange(
slice: ChunkSliceJson,
Expand Down Expand Up @@ -764,9 +798,10 @@ export async function renderChunk(
// directly. The existing adaptive-retry path reduces workers if
// compositor contention surfaces as CDP timeouts.
const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
const machineSizing = computeWorkerSizing(captureFrames, undefined, cfg);
const chunkWorkerCount = resolveChunkCaptureWorkers(
captureFrames,
calculateOptimalWorkers(captureFrames, undefined, cfg),
machineSizing.workers,
options?.maxCaptureWorkers,
);

Expand Down Expand Up @@ -1200,6 +1235,18 @@ export async function renderChunk(
ffmpegVersion,
};
writeFileSync(perfPath, `${JSON.stringify(perfPayload, null, 2)}\n`, "utf-8");
log.info(
"[renderChunk] capture sizing",
chunkCaptureSizingLog({
chunkIndex,
framesEncoded,
workers: chunkWorkerCount,
machineSizing,
maxCaptureWorkers: options?.maxCaptureWorkers,
captureMode,
captureStageMs,
}),
);

// Clean up only after the hash + perf sidecar landed. Any failure above
// leaves the framesDir in place for inspection.
Expand Down
Loading