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

opened this

Merged 11h 22m ago, live in production

mason/forge:mason/18026-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 0 commits fork

  • Merged. mason/18026-sentinel-shared-01m23vygyffx5hg2f5vm8r74 was merged into main as c5a926e.

Review

Sign in to review this change.
2 files changed +27 −6
src/kernel/statement_log.ts +9 −3
@@ -4,18 +4,24 @@
44 * A budget in CPU time moved with the machine: the same page read 12 to 22 reference units on a
55 * Mac and 34 to 39 on a many-core runner. The statements a page asks for do not move. But the
66 * 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
99 * `FORGE_STATEMENT_LOG`, read once when the connection is wrapped; a worker inherits the variable.
1010 * Unset (production), nothing is read or written. The test owns the file; it is never under the
1111 * 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.
1216 */
1317
1418 import { appendFileSync } from "node:fs";
19 import { readStep, stepMemory } from "./loop_step.ts";
1520
1621 /** The function that records one statement text on a connection made now, or none. */
1722 export function statementLogger(): ((sql: string) => void) | undefined {
1823 const path = process.env["FORGE_STATEMENT_LOG"];
1924 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`);
2127 }
test/observability-budget.test.ts +18 −3
@@ -20,6 +20,7 @@ import { serve, type Servers } from "../src/http/server.ts";
2020 import { clearMapCache } from "../src/web/map_cache.ts";
2121 import { kpiCache, panelCache } from "../src/web/studio/home_cache.ts";
2222 import { p75 } from "../src/flow/reach.ts";
23 import { background } from "../src/perf/jobs.ts";
2324 import { seedAdmin } from "./helpers/admin.ts";
2425 import { seedFlowFixture } from "./helpers/flow-fixture.ts";
2526 import { SCRATCH_ROOT, scratchDir } from "./helpers/scratch.ts";
@@ -50,10 +51,16 @@ afterAll(async () => {
5051 if (dataDir !== "") await rm(dataDir, { recursive: true, force: true });
5152 });
5253
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 */
5459 function readStatementLog(path: string): string[] {
5560 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);
5764 }
5865
5966 /** `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 {
122129 /**
123130 * The ceilings are counts, the same on every machine: what the page asks for does not depend on
124131 * 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`
126134 * is a pass whatever the machine.
127135 */
128136 function withinWork(work: Work, ceiling: { statements: number; runPasses: number }): void {
@@ -173,6 +181,13 @@ describe("on production's size", () => {
173181 withinWork(res.work, { statements: 240, runPasses: 0 });
174182 });
175183
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
176191 test("the count sees a scan the rows returned would hide, and not a probe", () => {
177192 const scan = workOf(["SELECT COUNT(*) FROM run", "SELECT SUM(id) FROM run r WHERE r.branch = 'x'"]);
178193 expect(scan.runPasses).toBe(2);

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

Keyboard shortcuts

Docs