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

The snapshot stream blocks the forge's event loop #17629

Closed opened this

Picked up by torque; no pull came of it (ok) · 2 runs · run

opened this

Every page and API call can wait behind the forge's event loop, and the snapshot stream is the biggest thing holding it.

Measured on production (read-only), 17:05-19:05 UTC on 2026-12-02

The forge's own [loop] event loop blocked log: 319 stalls over 200 ms in two hours, about 210 s blocked (about 3% of the loop). Ranked:

  1. The snapshot stream (#16858). 55 stalls (34.6 s) with nothing running but the stream, up to 1.5 s each. During one pass the main heap went from 357 to 1,644 MiB in 70 s, with stalls of 0.2-3.5 s blamed on whatever request was in flight, until a collection ran.
  2. The boot after a release. Stalls of 0.5-2.0 s for about two minutes after each boot (52.7 s blocked in the 180 s after the 19:41 boot). Releases come every 30 minutes.
  3. The series sampler. 230-560 ms every 30 s (fixed in #17600: two indexes, 253 -> 53 ms).
  4. Requests. pulls/:number/files and pulls/:number up to 3-4 s, mostly overlapping the stream's heap growth.

Why the stream blocks

For every file of every hosted forge, every 5 minutes, the main thread read the file, 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, about 5% copies and reads. Almost all of it is for chunks the store already holds.

The fix (#17622)

The cut runs in a worker (src/snapshot/cut_worker.ts, src/snapshot/cut.ts). The worker reads, cuts and hashes, and answers chunk names and lengths only; the main thread reads by offset only the chunks the store lacks and checks each against its name.

Runner-6, one hosted forge of 170 MiB (a 96 MiB database, 900 run logs), steady passes, two rounds:

beforeafter
loop blocked a pass750-864 ms (11 stalls over 50 ms, max 77-124 ms)0 ms (max 12-34 ms)
heap + external peak188-223 MiB23-50 MiB
pass time3.2-3.6 s3.9-4.7 s

Restore proof on runner-6: a 226 MB hosted forge (96 MiB database, a repository of 32 commits, 901 run logs) plus the forge's own drop files, three files changed between their cut and their read; restored through restoreSnapshot and restoreHostedInto: 922 of 922 files byte-identical (SHA-256), the database's rows identical, the repository's refs and tree identical, git fsck --full clean.

2 earlier comments
commented

Parked by the crew: the run ended without a pull: declined: the fix this issue describes is pull #17622 ("A snapshot's files are cut off the serving thread…"), which is still open and not merged. src/snapshot/cut_worker.ts and cut.ts are not on main or o

commented

Done on main already, waiting for you to close it: 574b0212439180f4bb1e147af0a9529075c967ec

commented

Closed: already done on main in 574b021. Closed by the crew's live triage; reopen it to undo, and it stays open.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs