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
Check · Review · Land · Live done — Landed and live in production.
fix/cold-home-unit → main 0 commits
1 file
changed +32
−15
test/observability-budget.test.ts +32 −15
| @@ -5,7 +5,8 @@ | ||
| 5 | 5 | * and home 9.2 s. Each budget is a multiple of one full pass over the run |
| 6 | 6 | * table, timed in the same run, so a loaded machine slows both sides and |
| 7 | 7 | * 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. | |
| 9 | 10 | */ |
| 10 | 11 | import { forgetHome } from "../src/web/studio/home_last.ts"; |
| 11 | 12 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| @@ -42,11 +43,17 @@ afterAll(async () => { | ||
| 42 | 43 | if (dataDir !== "") await rm(dataDir, { recursive: true, force: true }); |
| 43 | 44 | }); |
| 44 | 45 | |
| 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. */ | |
| 46 | 53 | function scan(): number { |
| 47 | const started = performance.now(); | |
| 54 | const started = cpuMs(); | |
| 48 | 55 | app.db.query("SELECT COUNT(*), SUM(length(branch)), SUM(length(created_at)) FROM run").get(); |
| 49 | return performance.now() - started; | |
| 56 | return cpuMs() - started; | |
| 50 | 57 | } |
| 51 | 58 | |
| 52 | 59 | function baseline(): number { |
| @@ -54,11 +61,24 @@ function baseline(): number { | ||
| 54 | 61 | return spent[1]!; |
| 55 | 62 | } |
| 56 | 63 | |
| 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). */ | |
| 57 | 77 | async function get(path: string): Promise<{ ms: number; status: number; timing: string }> { |
| 58 | const started = performance.now(); | |
| 78 | const started = cpuMs(); | |
| 59 | 79 | const res = await fetch(`${servers.url}${path}`, { headers: { cookie } }); |
| 60 | 80 | 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") ?? "" }; | |
| 62 | 82 | } |
| 63 | 83 | |
| 64 | 84 | const names = (timing: string): string[] => timing.split(", ").map((p) => p.split(";")[0]!); |
| @@ -77,21 +97,19 @@ describe("on production's size", () => { | ||
| 77 | 97 | |
| 78 | 98 | test("/boards answers within a few passes over the runs, and names its phases", async () => { |
| 79 | 99 | await get("/boards"); |
| 80 | const unit = baseline(); | |
| 81 | const res = await get("/boards"); | |
| 100 | const res = await timedAgainstUnit("/boards"); | |
| 82 | 101 | expect(res.status).toBe(200); |
| 83 | 102 | 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); | |
| 85 | 104 | }); |
| 86 | 105 | |
| 87 | 106 | test("a cold /map answers within a few passes over the runs", async () => { |
| 88 | 107 | await get("/map"); |
| 89 | 108 | clearMapCache(); |
| 90 | const unit = baseline(); | |
| 91 | const res = await get("/map"); | |
| 109 | const res = await timedAgainstUnit("/map"); | |
| 92 | 110 | expect(res.status).toBe(200); |
| 93 | 111 | expect(names(res.timing)).toContain("layout"); |
| 94 | expect(res.ms).toBeLessThan(60 * unit); | |
| 112 | expect(res.ms).toBeLessThan(60 * res.unit); | |
| 95 | 113 | }); |
| 96 | 114 | |
| 97 | 115 | 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", () => { | ||
| 101 | 119 | app.db.run("UPDATE repo SET description = description || ''"); |
| 102 | 120 | for (const cache of [kpiCache(app.db), panelCache(app.db)]) cache.clear(); |
| 103 | 121 | forgetHome(app.db); |
| 104 | const unit = baseline(); | |
| 105 | const res = await get("/"); | |
| 122 | const res = await timedAgainstUnit("/"); | |
| 106 | 123 | expect(res.status).toBe(200); |
| 107 | 124 | // the home reads no table itself: the lanes' worker does, and the page is drawn from its picture |
| 108 | 125 | expect(names(res.timing)).toContain("picture"); |
| 109 | expect(res.ms).toBeLessThan(30 * unit); | |
| 126 | expect(res.ms).toBeLessThan(30 * res.unit); | |
| 110 | 127 | }); |
| 111 | 128 | }); |
| 112 | 129 |
new above
offline