Public: anyone can read this; the crew can change it.
Sentinel: memory-growth was degraded 16 minutes today: The forge's own memory is 4769 MiB, over twice its first-hour 1716 MiB and past the 2176 MiB more its database caches m… #17494
Merged 28h 51m ago, live in production
mason/forge:mason/17493-sentinel-memory-growth-was-degraded-16-m → main 0 commits fork
3 files
changed +31
−0
docs/features/memory-growth.md +2
| @@ -33,6 +33,8 @@ The sentinel's memory-growth issue quotes the watch's evidence: each VM's heap, | ||
| 33 | 33 | |
| 34 | 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 | 35 | |
| 36 | **The snapshot collects as it reads (#17493).** The finding after that fix still had `snapshot-stream` open before the trip and the main heap at 416 MiB in the first hour, 2855 MiB at the trip and 462 MiB now: garbage again, held every count flat. One forge's pass cuts a multi-GiB database through fresh buffers, so collecting once per forge left the pile inside it. `takeSnapshot` now runs `Bun.gc(false)` each 256 MiB of plain bytes read (`settle`, `settleBytes` are its test seams). Not measured on production's data: the next finding's `memory heap main` line at the trip says whether it was the whole. Test: `test/snapshot-stream.test.ts`. | |
| 37 | ||
| 36 | 38 | 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. |
| 37 | 39 | |
| 38 | 40 | 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/snapshot.ts +19
| @@ -348,8 +348,17 @@ export interface Snapshotter { | ||
| 348 | 348 | * next one lists afresh. |
| 349 | 349 | */ |
| 350 | 350 | readonly chunks?: ChunkView | undefined; |
| 351 | /** | |
| 352 | * Test seams for the collection inside one forge's pass (#17493): `settle` runs each time | |
| 353 | * `settleBytes` more plain bytes were read. Default: `Bun.gc(false)` every 256 MiB. | |
| 354 | */ | |
| 355 | readonly settle?: (() => void) | undefined; | |
| 356 | readonly settleBytes?: number | undefined; | |
| 351 | 357 | } |
| 352 | 358 | |
| 359 | /** Plain bytes read between two collections inside one snapshot. */ | |
| 360 | const SETTLE_BYTES = 256 * 1024 * 1024; | |
| 361 | ||
| 353 | 362 | /** |
| 354 | 363 | * What a run of snapshots knows of the store's chunks between them: `keys` as `list` gave them, |
| 355 | 364 | * or undefined when the next must list. |
| @@ -505,7 +514,17 @@ export async function takeSnapshot( | ||
| 505 | 514 | let there = new Set<string>(); |
| 506 | 515 | let found = 0; |
| 507 | 516 | // One chunk: its name, and its bytes to the queue unless the store has them. |
| 517 | const settleAt = forge.settleBytes ?? SETTLE_BYTES; | |
| 518 | const settle = forge.settle ?? ((): void => void Bun.gc(false)); | |
| 519 | let settledAt = 0; | |
| 508 | 520 | const send = async (plain: Uint8Array): Promise<string> => { |
| 521 | // A forge of several GiB cuts every chunk through fresh buffers; the collector lets them pile | |
| 522 | // up for the whole forge (#17493: the main heap 416 to 2855 MiB inside one pass), so it runs | |
| 523 | // each `settleAt` bytes read, not once per forge. | |
| 524 | if (readBytes - settledAt >= settleAt) { | |
| 525 | settledAt = readBytes; | |
| 526 | settle(); | |
| 527 | } | |
| 509 | 528 | const id = chunkId(plain); |
| 510 | 529 | const key = await storedChunk(store, id); |
| 511 | 530 | if (there.has(key)) { |
test/snapshot-stream.test.ts +10
| @@ -123,6 +123,16 @@ describe("the stream of hosted forges", () => { | ||
| 123 | 123 | expect(seen).toEqual(["take kid", "settle", "take kid", "settle"]); |
| 124 | 124 | }); |
| 125 | 125 | |
| 126 | test("a forge's pass collects as it reads, not only when it ends (#17493)", async () => { | |
| 127 | const store = dirStore(join(root, `store-${n++}`)); | |
| 128 | let ran = 0; | |
| 129 | await takeSnapshot({ ...shape(), stream: "kid", settle: () => void ran++, settleBytes: 1 }, store); | |
| 130 | expect(ran).toBeGreaterThan(0); | |
| 131 | let none = 0; | |
| 132 | await takeSnapshot({ ...shape(), stream: "kid", settle: () => void none++, settleBytes: 2 ** 40 }, store); | |
| 133 | expect(none).toBe(0); | |
| 134 | }); | |
| 135 | ||
| 126 | 136 | test("a refused copy keeps the last good manifest and its time, and says why (#16977)", async () => { |
| 127 | 137 | const store = dirStore(join(root, `store-${n++}`)); |
| 128 | 138 | await pass(store, new Date("2026-11-30T10:00:00Z")); |
new above
offline