Public: anyone can read this; the crew can change it.
Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:sh74wg48ib is past its budget: trevato/forge: "on production's size > a cold /map answers within a few passes over the runs" failed on 3 pulls in the … #18070
Merged 11h 22m ago, live in production
mason/forge:mason/18026-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 0 commits fork
2 files
changed +27
−6
src/kernel/statement_log.ts +9 −3
| @@ -4,18 +4,24 @@ | ||
| 4 | 4 | * A budget in CPU time moved with the machine: the same page read 12 to 22 reference units on a |
| 5 | 5 | * Mac and 34 to 39 on a many-core runner. The statements a page asks for do not move. But the |
| 6 | 6 | * lanes, pipeline and pages workers open connections of their own, so a counter wrapped round the |
| 7 | * main handle misses most of a cold page. Every wrapped connection (`keepFixedTexts`) appends the | |
| 8 | * text of each statement it is asked for, one JSON string a line, to the file named by | |
| 7 | * main handle misses most of a cold page. Every wrapped connection (`keepFixedTexts`) appends each | |
| 8 | * statement it is asked for, one JSON line `{"sql", "step"}`, to the file named by | |
| 9 | 9 | * `FORGE_STATEMENT_LOG`, read once when the connection is wrapped; a worker inherits the variable. |
| 10 | 10 | * Unset (production), nothing is read or written. The test owns the file; it is never under the |
| 11 | 11 | * app's data. |
| 12 | * | |
| 13 | * `step` is what the thread was doing (`kernel/loop_step.ts`): `duty <name>` while a background | |
| 14 | * job's synchronous part runs, so a timer that fires mid-page (a flush of request counts) is told | |
| 15 | * from the page's own statements, whatever the machine's load (#18026). "" when nothing is named. | |
| 12 | 16 | */ |
| 13 | 17 | |
| 14 | 18 | import { appendFileSync } from "node:fs"; |
| 19 | import { readStep, stepMemory } from "./loop_step.ts"; | |
| 15 | 20 | |
| 16 | 21 | /** The function that records one statement text on a connection made now, or none. */ |
| 17 | 22 | export function statementLogger(): ((sql: string) => void) | undefined { |
| 18 | 23 | const path = process.env["FORGE_STATEMENT_LOG"]; |
| 19 | 24 | if (path === undefined || path === "") return undefined; |
| 20 | return (sql) => appendFileSync(path, `${JSON.stringify(sql)}\n`); | |
| 25 | const steps = stepMemory(); | |
| 26 | return (sql) => appendFileSync(path, `${JSON.stringify({ sql, step: readStep(steps) })}\n`); | |
| 21 | 27 | } |
test/observability-budget.test.ts +18 −3
| @@ -20,6 +20,7 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 20 | 20 | import { clearMapCache } from "../src/web/map_cache.ts"; |
| 21 | 21 | import { kpiCache, panelCache } from "../src/web/studio/home_cache.ts"; |
| 22 | 22 | import { p75 } from "../src/flow/reach.ts"; |
| 23 | import { background } from "../src/perf/jobs.ts"; | |
| 23 | 24 | import { seedAdmin } from "./helpers/admin.ts"; |
| 24 | 25 | import { seedFlowFixture } from "./helpers/flow-fixture.ts"; |
| 25 | 26 | import { SCRATCH_ROOT, scratchDir } from "./helpers/scratch.ts"; |
| @@ -50,10 +51,16 @@ afterAll(async () => { | ||
| 50 | 51 | if (dataDir !== "") await rm(dataDir, { recursive: true, force: true }); |
| 51 | 52 | }); |
| 52 | 53 | |
| 53 | /** The statement texts in the log at `path`, one per statement asked for, in order. */ | |
| 54 | /** | |
| 55 | * The statement texts in the log at `path` that the page asked for, in order. A background job's | |
| 56 | * (`duty <name>`) is the process's, not the page's: a timer that fires mid-request on a loaded | |
| 57 | * machine added 25 statements to a cold /map's 32 (#18026). | |
| 58 | */ | |
| 54 | 59 | function readStatementLog(path: string): string[] { |
| 55 | 60 | const text = readFileSync(path, "utf8"); |
| 56 | return text === "" ? [] : text.trimEnd().split("\n").map((line) => JSON.parse(line) as string); | |
| 61 | if (text === "") return []; | |
| 62 | const lines = text.trimEnd().split("\n").map((line) => JSON.parse(line) as { sql: string; step: string }); | |
| 63 | return lines.filter((l) => !l.step.startsWith("duty ")).map((l) => l.sql); | |
| 57 | 64 | } |
| 58 | 65 | |
| 59 | 66 | /** `path` fetched, and what it did: the statements it asked for and how long the server took. */ |
| @@ -122,7 +129,8 @@ function workOf(texts: string[]): Work { | ||
| 122 | 129 | /** |
| 123 | 130 | * The ceilings are counts, the same on every machine: what the page asks for does not depend on |
| 124 | 131 | * how fast the machine answers. They sit above what each page asks for now (boards 56, map 32, |
| 125 | * home 177 statements) by room for the process's own background reads, and a pass over `run` | |
| 132 | * home 177 statements) by room for a background job's reads after an await, which no step names; | |
| 133 | * a background job's statements are not counted at all (`readStatementLog`), and a pass over `run` | |
| 126 | 134 | * is a pass whatever the machine. |
| 127 | 135 | */ |
| 128 | 136 | function withinWork(work: Work, ceiling: { statements: number; runPasses: number }): void { |
| @@ -173,6 +181,13 @@ describe("on production's size", () => { | ||
| 173 | 181 | withinWork(res.work, { statements: 240, runPasses: 0 }); |
| 174 | 182 | }); |
| 175 | 183 | |
| 184 | test("a background job's statements, asked for mid-page, are not the page's", async () => { | |
| 185 | writeFileSync(logPath, ""); | |
| 186 | await background("budget-probe", () => app.db.query("SELECT 1 AS budget_probe").get()); | |
| 187 | app.db.query("SELECT 2 AS budget_page").get(); | |
| 188 | expect(readStatementLog(logPath)).toEqual(["SELECT 2 AS budget_page"]); | |
| 189 | }); | |
| 190 | ||
| 176 | 191 | test("the count sees a scan the rows returned would hide, and not a probe", () => { |
| 177 | 192 | const scan = workOf(["SELECT COUNT(*) FROM run", "SELECT SUM(id) FROM run r WHERE r.branch = 'x'"]); |
| 178 | 193 | expect(scan.runPasses).toBe(2); |
new above
offline