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
3 changes: 3 additions & 0 deletions docs/internals/16_performance-regressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ heap, and first-request latency against a fake Anthropic API and the real `claud
isolated runs.
- Use `scaling` to separate per-thread cost from fixed server overhead, and `--soak <minutes>` to
spot rising heap slopes (leaks).
- Steer server work by `working`: many worktree threads editing files at once with one client
subscribed to all of them. Turns per minute that stay flat as threads are added mean the
server, not the agents, is the bottleneck.
- Test macOS, Windows, and Linux with `--no-agent-scope`: Linux systemd agent scopes mask
per-process polling paths that other platforms run.

Expand Down
54 changes: 52 additions & 2 deletions scripts/server-metrics-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const MachineState = Schema.Struct({
});
export type MachineState = typeof MachineState.Type;

const WorkingPoint = Schema.Struct({
...Window.fields,
/** Turns finished inside the window, per minute; higher is better. */
turnsPerMin: Schema.Number,
/** Send to the agent's first API request. */
toRequestMs: Spread,
/** The turn's last reply byte to the client seeing the run end. */
turnEndMs: Spread,
/** Send to the client seeing the run end. */
turnMs: Spread,
});
export type WorkingPoint = typeof WorkingPoint.Type;

/** One pass over the scenarios. */
export const Measured = Schema.Struct({
/** What else the machine was doing during the pass; never compared, only warned about. */
Expand All @@ -73,6 +86,21 @@ export const Measured = Schema.Struct({
}),
}),
),
/**
* N threads in worktrees of their own run editing turns back to back, all at once, with one
* web-like client subscribed to all of them. The scenario to steer server performance by.
*/
working: Schema.optional(
Schema.Struct({
/** Each window by the number of threads working in it. */
active: Schema.Record(Schema.String, WorkingPoint),
/** Fits over the windows: what each additional working thread costs. */
heapMBPerThread: Schema.Number,
rssMBPerThread: Schema.Number,
cpuPctPerThread: Schema.Number,
loopDelayP99MsPerThread: Schema.Number,
}),
),
/** 50 short turns back to back on one thread. */
pipeline: Schema.optional(
Schema.Struct({
Expand Down Expand Up @@ -244,6 +272,24 @@ export const NOISE_RULES: ReadonlyArray<NoiseRule> = [
{ pattern: /^scaling\.heapMBPerThread$/, floor: 0.06, gate: true },
{ pattern: /^scaling\.rssMBPerThread$/, floor: 0.2, gate: true },
{ pattern: /^soak\./, floor: 20, gate: true },
informational(/^working\.(cpuPct|loopDelayP99Ms)PerThread$/),
informational(/^working\.active\.\d+\.(wakeupsPerSec|loopDelayMaxMs|gcPauseMs)$/),
{ pattern: /^working\.heapMBPerThread$/, floor: 0.06, gate: true },
{ pattern: /^working\.rssMBPerThread$/, floor: 0.2, gate: true },
{ pattern: /^working\.active\.\d+\.turnsPerMin$/, floor: 4, gate: true },
{ pattern: /^working\.active\.\d+\.toRequestMs\.median$/, floor: 1_100, gate: true },
{ pattern: /^working\.active\.\d+\.turnEndMs\.median$/, floor: 1_700, gate: true },
{
pattern: /^working\.active\.\d+\.(toRequestMs\.p90|turnMs\.median)$/,
floor: 1_900,
gate: true,
},
{ pattern: /^working\.active\.\d+\.turnEndMs\.p90$/, floor: 2_200, gate: true },
{ pattern: /^working\.active\.\d+\.turnMs\.p90$/, floor: 2_800, gate: true },
// Peak RSS while 20 agents run swings by a checkpoint's git children; the settled RSS does not.
{ pattern: /^working\.active\.\d+\.rssPeakMB$/, floor: 170, gate: true },
{ pattern: /^working\.active\.\d+\.(cpuPct|loopDelayP99Ms)$/, floor: 5, gate: true },
{ pattern: /^working\.active\.\d+\.gcCount$/, floor: 8, gate: true },
{ pattern: /^startup\.readyMs$/, floor: 600, gate: true },
{ pattern: /^firstWord\./, floor: 600, gate: true },
{ pattern: /^pipeline\.(toRequestMs|turnEndMs)\.median$/, floor: 300, gate: true },
Expand All @@ -270,6 +316,9 @@ export function noiseRule(metric: string, rules: ReadonlyArray<NoiseRule> = NOIS
return rules.find((rule) => rule.pattern.test(metric)) ?? { floor: 0, gate: true };
}

/** Throughput, where a drop is the regression. */
export const higherIsBetter = (metric: string) => metric.endsWith("PerMin");

/** Fields that describe a run rather than measure it. */
const isMetric = (metric: string) =>
!(
Expand Down Expand Up @@ -465,7 +514,7 @@ export function compareMetrics(
const a = collect(before);
const b = collect(after);
const lines = [
"### Server metrics (lower is better)",
"### Server metrics (lower is better, except throughput per minute)",
"",
`before \`${before.meta.commit}\` (${before.runs.length} runs), after \`${after.meta.commit}\` (${after.runs.length} runs), ${after.meta.platform}${after.meta.noAgentScope ? ", no agent scope" : ""}`,
"",
Expand Down Expand Up @@ -499,7 +548,8 @@ export function compareMetrics(
const limit = Math.max(rule.floor, (Math.abs(mx) * threshold) / 100);
const repeated = x.length > 1 && y.length > 1;
const [low, high] = repeated ? bootstrapMedianDifference(x, y) : [my - mx, my - mx];
const moved = low > limit ? "worse" : high < -limit ? "better" : "";
const up = low > limit ? "worse" : high < -limit ? "better" : "";
const moved = higherIsBetter(metric) ? { worse: "better", better: "worse", "": "" }[up] : up;
if (moved && !rule.gate) informational.push(metric);
else if (moved === "worse") regressed.push(metric);
else if (moved === "better") improved.push(metric);
Expand Down
41 changes: 41 additions & 0 deletions scripts/server-metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,47 @@ describe("noiseReport", () => {
});
});

describe("compareMetrics on working throughput", () => {
const working = (turnsPerMin: number) =>
({
meta,
runs: [
{
working: {
active: {
"20": {
...loopAtRest,
cpuPct: 90,
wakeupsPerSec: 1_600,
rssPeakMB: 700,
rssMB: 560,
heapAfterGcMB: 218,
turnsPerMin,
toRequestMs: { median: 4_000, p90: 9_000 },
turnEndMs: { median: 16_000, p90: 25_000 },
turnMs: { median: 24_000, p90: 36_000 },
},
},
heapMBPerThread: 0.2,
rssMBPerThread: 0.8,
cpuPctPerThread: 0,
loopDelayP99MsPerThread: 0,
},
},
],
}) satisfies ServerMetrics;
const rules = [{ pattern: /turnsPerMin$/, floor: 2, gate: true }];
it.each([
["fewer turns a minute", 20, ["working.active.20.turnsPerMin"], []],
["more turns a minute", 45, [], ["working.active.20.turnsPerMin"]],
["a move under the floor", 34, [], []],
])("%s", (_name, turnsPerMin, regressed, improved) => {
const result = compareMetrics(working(33), working(turnsPerMin), 5, rules);
expect(result.regressed).toEqual(regressed);
expect(result.improved).toEqual(improved);
});
});

describe("compareMetrics on the busy shell snapshot", () => {
const window = { cpuPct: 1, wakeupsPerSec: 10, rssPeakMB: 500, rssMB: 500, heapAfterGcMB: 200 };
const busyRun = (shellMs: number, shellKB: number) =>
Expand Down
Loading
Loading