Public: anyone can read this; the crew can change it.

The production-size page budgets count CPU on both sides, the unit read around the page #16981

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

fix/cold-home-unit → main 0 commits

  • Merged. fix/cold-home-unit was merged into main as 4cf0ee7.

Review

Sign in to review this change.
1 file changed +32 −15
test/observability-budget.test.ts +32 −15
@@ -5,7 +5,8 @@
55 * and home 9.2 s. Each budget is a multiple of one full pass over the run
66 * table, timed in the same run, so a loaded machine slows both sides and
77 * the wall clock is never the judge (#3069). Before the fix each page cost
8 * hundreds of those passes.
8 * hundreds of those passes. Both sides are process CPU time (the server and its workers run in
9 * this process), so a busy runner's waiting counts on neither side.
910 */
1011 import { forgetHome } from "../src/web/studio/home_last.ts";
1112 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
@@ -42,11 +43,17 @@ afterAll(async () => {
4243 if (dataDir !== "") await rm(dataDir, { recursive: true, force: true });
4344 });
4445
45 /** One full pass over every run: the unit the budgets are counted in. */
46 /** The process's CPU time, in ms: the server, its workers and this test all run in it. */
47 const cpuMs = (): number => {
48 const used = process.cpuUsage();
49 return (used.user + used.system) / 1000;
50 };
51
52 /** One full pass over every run, in CPU ms: the unit the budgets are counted in. */
4653 function scan(): number {
47 const started = performance.now();
54 const started = cpuMs();
4855 app.db.query("SELECT COUNT(*), SUM(length(branch)), SUM(length(created_at)) FROM run").get();
49 return performance.now() - started;
56 return cpuMs() - started;
5057 }
5158
5259 function baseline(): number {
@@ -54,11 +61,24 @@ function baseline(): number {
5461 return spent[1]!;
5562 }
5663
64 /**
65 * `path` timed, with the unit measured on both sides of it and the larger kept. CPU time still
66 * stretches a little on a contended machine (caches, cores); the unit read after the page shares
67 * whatever contention the page met. The wall clock read a cold home at 773 ms against a 739 ms
68 * budget on a busy runner (#16696); in CPU, waiting counts on neither side.
69 */
70 async function timedAgainstUnit(path: string): Promise<{ ms: number; status: number; timing: string; unit: number }> {
71 const before = baseline();
72 const res = await get(path);
73 return { ...res, unit: Math.max(before, baseline()) };
74 }
75
76 /** `path` fetched; `ms` is the CPU the process spent answering it (its workers' included). */
5777 async function get(path: string): Promise<{ ms: number; status: number; timing: string }> {
58 const started = performance.now();
78 const started = cpuMs();
5979 const res = await fetch(`${servers.url}${path}`, { headers: { cookie } });
6080 await res.arrayBuffer();
61 return { ms: performance.now() - started, status: res.status, timing: res.headers.get("server-timing") ?? "" };
81 return { ms: cpuMs() - started, status: res.status, timing: res.headers.get("server-timing") ?? "" };
6282 }
6383
6484 const names = (timing: string): string[] => timing.split(", ").map((p) => p.split(";")[0]!);
@@ -77,21 +97,19 @@ describe("on production's size", () => {
7797
7898 test("/boards answers within a few passes over the runs, and names its phases", async () => {
7999 await get("/boards");
80 const unit = baseline();
81 const res = await get("/boards");
100 const res = await timedAgainstUnit("/boards");
82101 expect(res.status).toBe(200);
83102 for (const n of ["session", "picture", "flow", "render"]) expect(names(res.timing)).toContain(n);
84 expect(res.ms).toBeLessThan(30 * unit);
103 expect(res.ms).toBeLessThan(30 * res.unit);
85104 });
86105
87106 test("a cold /map answers within a few passes over the runs", async () => {
88107 await get("/map");
89108 clearMapCache();
90 const unit = baseline();
91 const res = await get("/map");
109 const res = await timedAgainstUnit("/map");
92110 expect(res.status).toBe(200);
93111 expect(names(res.timing)).toContain("layout");
94 expect(res.ms).toBeLessThan(60 * unit);
112 expect(res.ms).toBeLessThan(60 * res.unit);
95113 });
96114
97115 test("a cold home answers from the picture, within a few passes over the runs", async () => {
@@ -101,12 +119,11 @@ describe("on production's size", () => {
101119 app.db.run("UPDATE repo SET description = description || ''");
102120 for (const cache of [kpiCache(app.db), panelCache(app.db)]) cache.clear();
103121 forgetHome(app.db);
104 const unit = baseline();
105 const res = await get("/");
122 const res = await timedAgainstUnit("/");
106123 expect(res.status).toBe(200);
107124 // the home reads no table itself: the lanes' worker does, and the page is drawn from its picture
108125 expect(names(res.timing)).toContain("picture");
109 expect(res.ms).toBeLessThan(30 * unit);
126 expect(res.ms).toBeLessThan(30 * res.unit);
110127 });
111128 });
112129

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs