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

Merged opened this

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

Merged

scout/forge:scout/17043-sentinel-shared-01m23vygyffx5hg2f5vm8r74 → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/17043-sentinel-shared-01m23vygyffx5hg2f5vm8r74 was merged into main as 641b5c0.

Review

Sign in to review this change.
2 files changed +18 −4
src/flow/slots.ts +4 −4
@@ -130,15 +130,15 @@ function rows(db: Database, since: string): Row[] {
130130 /** The line for one kind of run, read from its rows at `now`. Pure: rows in, figures out. */
131131 export function slotLine(kind: SlotLine["kind"], slots: number, runs: readonly Row[], now: number): SlotLine {
132132 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) }));
133136 const points: SlotPoint[] = [];
134137 for (let i = SLOT_POINTS - 1; i >= 0; i--) {
135138 const at = now - i * STEP_MS;
136139 let running = 0;
137140 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) {
142142 if (started <= at && at < ended) running++;
143143 else if (asked <= at && at < Math.min(started, ended)) queued++;
144144 }
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
5656 expect(isFull({ ...l, busy: 1 })).toBe(false);
5757 });
5858
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);

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.

71 });
72
5973 test("drawn, a full lane reads as full: the danger badge, solid bars at the line, the setting dashed across", () => {
6074 const full: SlotLine = {
6175 ...slotLine("checks", 4, [], NOW),

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

Keyboard shortcuts

Docs