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

A snapshot's files are cut off the serving thread: an unchanged hosted forge's stream pass holds the loop 0 ms, not 0.8 s #17622

opened this

Merged 12h 32m ago, live in production

This touches backups: snapshot integrity is the first thing to review (chunk names checked on read, the changed-file path, the hosted forge fd boundary).

Notes

opened this

This touches backups: snapshot integrity is the first thing to review (chunk names checked on read, the changed-file path, the hosted forge fd boundary).

Production's loop log, 17:05-19:05: 55 stalls (34.6 s) with nothing running but the snapshot stream, up to 1.5 s, and during one pass the main heap went 357 -> 1,644 MiB with stalls to 3.5 s blamed on whatever request was in flight. The stream takes every hosted forge every 5 minutes, and for every file the main thread read it (1 MiB at a time), cut it (a JS rolling hash for content cuts), hashed every byte twice (the file's SHA-256 and each chunk's) and copied each chunk out. A JSC sample of a steady pass on a runner: 29% the content cut, 26% chunk hashes, 26% file hashes, the rest the reads and copies. Almost all of it is for chunks the store already holds.

Scope, of the two ways: zero-copy streaming would only remove the copies (about 5%: the cut and the hashes stay on this thread). A worker removes all of it, so the worker it is, the least machinery that does: cut_worker.ts reads a file through one buffer, cuts and hashes it, and answers the chunks' names and lengths, never their bytes (cut.ts, one worker for a snapshot, closed with it). The main thread then reads by offset only the chunks the store lacks, checks each against its name, and sends it as before. What is read now that is not what was cut (the file changed under the cut): a hosted forge's file says so, as before, and its caller reads it again; any other file is read here whole, the old way. A hosted forge's descriptor goes to the worker as is, so the read stays inside its directory.

The 512 MiB forced collection: the in-snapshot settle now counts bytes held on this thread (a chunk sent, or bytes put whole), not bytes read, so a pass that sends nothing never collects; the stream's per-forge settle stays as it is and, with nothing held, has nothing to force.

Measured on runner-6, one hosted forge of production's size (170 MiB: a 96 MiB database, a 32 MiB repository, 900 run logs), four passes each, two rounds, steady passes 2-4: loop blocked 750-864 ms a pass (11 stalls over 50 ms, max 77-124 ms) -> 0 ms (0 stalls, max 12-34 ms) heap + external peak 188-223 MiB -> 23-50 MiB pass time 3.2-3.6 s -> 3.9-4.7 s (the worker's reads; nothing waits on a pass) Production ran six to eight such forges a pass.

test/snapshot-cut.test.ts: the worker's chunks are the main thread's, by name, length and order, for both cuts across its read boundary, with the file's hash; a missing file and a cut out at close are refused. test/snapshot-stream.test.ts: an unchanged forge's pass holds no byte on the main thread (it fails on the old code). 428 pass across the 59 snapshot, hosted, drill, backup and bundle files.

Co-Authored-By: Claude Fable 5 <[email protected]>

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs