Public: anyone can read this; the crew can change it.

Sentinel: memory-growth was degraded 18 minutes today: The forge's own memory is 5017 MiB, over twice its first-hour 1654 MiB and past the 2176 MiB more its database caches m… #17436

opened this

Merged 36h 11m ago, live in production

mason/forge:mason/17434-sentinel-memory-growth-was-degraded-18-m → main 0 commits fork 1 thread · 1 unresolved

  • Merged. mason/17434-sentinel-memory-growth-was-degraded-18-m was merged into main as baf03ad.

Review

Sign in to review this change.
3 files changed +21 −0
docs/features/memory-growth.md +2
@@ -31,6 +31,8 @@ The sentinel's memory-growth issue quotes the watch's evidence: each VM's heap,
3131
3232 **The stream pass open across the trip (#17205).** The first finding with the jobs open at the trip named one: `snapshot-stream`, begun 20:27:01, two minutes before RSS stood at 5458 MiB with the main heap at 140 MiB just after a collection, and still open seven minutes later (a pass runs every five). Each hosted forge in a pass listed the bucket's whole `chunks/` prefix twice: once for the chunks already there, once for the check before its manifest. Each listing is a `Set` of every key the bucket holds, and the bucket gains keys all day until the nightly sweep. A pass's forges now share one view (`ChunkView` in `snapshot/snapshot.ts`): the first lists, each forge's check listing is the next forge's start, and a forge that throws leaves the view empty, so the next lists afresh. A pass of N forges lists N + 1 times, not 2N. The check before each manifest is still a fresh listing. Measured off production, one listing of 300,000 keys cost about 100 MiB of heap and was collected, so this cuts the churn but does not prove the stream is the whole of the growth; the next finding's `jobs open at the trip` says whether `snapshot-stream` is still there. Test: `test/snapshot-stream.test.ts`.
3333
34 **The stream pass collects between forges (#17434).** The next finding named `snapshot-stream` again, open across the trip, with the main heap at 595 MiB in the first hour, 2587 MiB at the trip and 513 MiB afterwards: garbage, not a holder (every held count flat). A pass over N forges lists the bucket N + 1 times and cuts every chunk through fresh buffers, and the collector let a whole pass's worth pile up before it ran. `streamPass` now runs `Bun.gc(false)` after each forge, so the peak is one forge's garbage, not the pass's. Not measured on production's data: the next finding's `memory heap main` line at the trip says whether this was the whole of it. Test: `test/snapshot-stream.test.ts`.
35
3436 A restart between the growth and the filing (a release restarts the forge several times a day) leaves a watch that never saw it: the sentence is the stored one of the process that grew, and its own evidence would say `trip none`. So each minute the need is open, the sampler writes the watch's evidence to `memory-kept.json` under the data directory (`perf/memory_kept.ts`, #16872); a finding filed by a later process that has not tripped quotes those lines, kept that day, under `memory kept by the process started …, at its last grown minute …; the forge restarted since`, and ends with one `memory now (process started …)` line for the process reading it.
3537
3638 The need clears by itself once RSS falls under twice the baseline. A process that slept through its first hour has no baseline and raises none.
src/snapshot/stream.ts +10
@@ -75,6 +75,11 @@ export function streamLag(dataDir: string, now = Date.now()): StreamLag[] {
7575 .sort((a, b) => (a.name < b.name ? -1 : 1));
7676 }
7777
78 /** A collection between forges: not forced to be full, so the loop is held briefly. */
79 const collectGarbage = (): void => {
80 Bun.gc(false);
81 };
82
7883 /**
7984 * One pass over every hosted forge, one after another. `take` stores one forge and answers the
8085 * bytes it holds, or throws; a forge that throws costs that forge, never the pass. A forge that is
@@ -84,6 +89,7 @@ export async function streamPass(
8489 dataDir: string,
8590 take: (name: string) => Promise<{ readonly bytes: number; readonly hosted?: readonly { readonly why?: string | undefined }[] | undefined }>,
8691 now: () => Date = () => new Date(),
92 settle: () => void = collectGarbage,
8793 ): Promise<StreamEntry[]> {
8894 const before = new Map(readStream(dataDir).map((e) => [e.name, e]));
8995 const out: StreamEntry[] = [];
@@ -97,6 +103,10 @@ export async function streamPass(
97103 const was = before.get(name);
98104 out.push({ name, ...(was?.at === undefined ? {} : { at: was.at }), ...(was?.bytes === undefined ? {} : { bytes: was.bytes }), error: String(error instanceof Error ? error.message : error).slice(0, 200) });
99105 }
106 // A forge's pass leaves the bucket's listings (a Set of every chunk key, twice) and its
107 // chunks' buffers behind; the next forge's would pile on them until the collector next ran
108 // (#17434: the main heap 595 to 3700 MiB inside one pass).

Nit: "595 to 3700 MiB" disagrees with the 2587 MiB at the trip in docs/features/memory-growth.md and in the pull description. Use one figure.

109 settle();
100110 noteStream(dataDir, [...out, ...[...before.values()].filter((e) => !out.some((o) => o.name === e.name))]);
101111 }
102112 noteStream(dataDir, out);
test/snapshot-stream.test.ts +9
@@ -114,6 +114,15 @@ describe("the stream of hosted forges", () => {
114114 expect(late?.late).toBe(true);
115115 });
116116
117 test("the pass lets go of a forge's garbage before the next forge, failed or whole (#17434)", async () => {
118 const store = dirStore(join(root, `store-${n++}`));
119 const seen: string[] = [];
120 const settle = () => void seen.push("settle");
121 await streamPass(parent.config.dataDir, async (name) => { seen.push(`take ${name}`); throw new Error("no"); }, () => new Date(), settle);
122 await streamPass(parent.config.dataDir, (name) => { seen.push(`take ${name}`); return takeSnapshot({ ...shape(), stream: name }, store); }, () => new Date(), settle);
123 expect(seen).toEqual(["take kid", "settle", "take kid", "settle"]);
124 });
125
117126 test("a refused copy keeps the last good manifest and its time, and says why (#16977)", async () => {
118127 const store = dirStore(join(root, `store-${n++}`));
119128 await pass(store, new Date("2026-11-30T10:00:00Z"));

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

Keyboard shortcuts

Docs