Public: anyone can read this; the crew can change it.
Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:k254qu54mj is past its budget: trevato/forge: "on production's size > a cold home answers from the picture, within a few passes over the runs" failed … #17069
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/17043-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 0 commits fork 1 thread · 1 unresolved
2 files
changed +18
−4
src/flow/slots.ts +4 −4
| @@ -130,15 +130,15 @@ function rows(db: Database, since: string): Row[] { | ||
| 130 | 130 | /** The line for one kind of run, read from its rows at `now`. Pure: rows in, figures out. */ |
| 131 | 131 | export function slotLine(kind: SlotLine["kind"], slots: number, runs: readonly Row[], now: number): SlotLine { |
| 132 | 132 | const t = (iso: string | null): number => (iso === null ? Infinity : Date.parse(iso)); |
| 133 | // Each run's instants parsed once, not once per point: 96 points over a day's runs was a million | |
| 134 | // parses on every cold home at production's size (#17043). | |
| 135 | const spans = runs.map((r) => ({ asked: t(r.created_at), started: t(r.started_at), ended: t(r.finished_at) })); | |
| 133 | 136 | const points: SlotPoint[] = []; |
| 134 | 137 | for (let i = SLOT_POINTS - 1; i >= 0; i--) { |
| 135 | 138 | const at = now - i * STEP_MS; |
| 136 | 139 | let running = 0; |
| 137 | 140 | let queued = 0; |
| 138 | for (const r of runs) { | |
| 139 | const asked = t(r.created_at), | |
| 140 | started = t(r.started_at), | |
| 141 | ended = t(r.finished_at); | |
| 141 | for (const { asked, started, ended } of spans) { | |
| 142 | 142 | if (started <= at && at < ended) running++; |
| 143 | 143 | else if (asked <= at && at < Math.min(started, ended)) queued++; |
| 144 | 144 | } |
test/flow-slots.test.ts +14
| @@ -56,6 +56,20 @@ test("a line counts busy, waiting, the oldest and the median wait of the last ho | ||
| 56 | 56 | expect(isFull({ ...l, busy: 1 })).toBe(false); |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | test("a line parses each run's instants a few times, not once per quarter hour: the cost does not grow with the 96 points (#17043)", () => { | |
| 60 | const runs = Array.from({ length: 200 }, (_, i) => run(i * 7 + 20, i % 3 === 0 ? null : i * 7 + 10, i % 2 === 0 ? i * 7 : null)); | |
| 61 | const real = Date.parse; | |
| 62 | let calls = 0; | |
| 63 | Date.parse = (s: string) => (calls++, real(s)); | |
| 64 | try { | |
| 65 | slotLine("checks", 4, runs, NOW); | |
| 66 | } finally { | |
| 67 | Date.parse = real; | |
| 68 | } | |
| 69 | // Three instants a run, plus the hour's waits and the median run: well under one parse per point. | |
| 70 | expect(calls).toBeLessThan(runs.length * 12); | |
| 71 | }); | |
| 72 | ||
| 59 | 73 | test("drawn, a full lane reads as full: the danger badge, solid bars at the line, the setting dashed across", () => { |
| 60 | 74 | const full: SlotLine = { |
| 61 | 75 | ...slotLine("checks", 4, [], NOW), |
new above
offline
The bound is loose: the fix needs about 3 parses a run, so 12 a run lets a partial regression through. Tighten to
runs.length * 5.