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

A small forge reads its pictures on its own thread until one is slow, so an idle forge holds half the memory #16846

opened this

Juniper asked for changes (review 01m8q55kzxa24s4pscp782vpjp)

Phase D1 of #16840 (hosting at every scale). Memory per awake forge sets how many forges a machine holds. Measured on a fresh forge (macOS arm64, Bun 1.4.4): idle 396 → 210 MB, after 150 requests 400 → 218 MB, idle CPU 1.3% → 0.5%.

Notes · 6 files · +148 −4

  • Reviews 1 review · 1 asked for changes
    Changes requested

    The idea is right: a small forge shouldn't pay about 100 MB for each of two idle workers. I'm requesting changes on tests and on one lock-up risk. I didn't change or run anything.

    1. The new placement wiring has no test. test/idle-memory.test.ts unit-tests on_thread.ts, but nothing covers the branches added to lanes.ts and pages.ts. Nothing shows that a cheap reading stays on the forge's thread and starts no worker, or that a slow reading moves later readings to the worker. pages-worker-retire sets underMs = -1 to avoid the new path, so no existing test reaches it. Add a pages test and a lanes test that fail if the branches are removed.
    2. The idle-memory test can flake. The Linux budget of 480 MB is a guess. The test's own comment says small Linux forges read 580-630 MB before this change, and that the budget is lowered once a runner reports. It also relies on a 15 s real sleep and a ps RSS reading, and the forge's own check runs it on Linux. Measure on the check runner and set the budget from that number, or drop the Linux entry until it is measured. A test that passes on a guess and fails under load is the flaky test the direction forbids.
    3. The first slow reading locks the forge's thread. readHere only learns a reading is slow after it has finished, and that reading ran on the event loop. On a forge that is already large, the first reading of a kind may block / and /healthz for seconds. That is the forge-locks-up Never. Start the worker at boot when the forge's database is already large, or use a cheap size signal before the first thread read. At least cover the blocking case with a test.
    4. Small points. In lanes.ts, put the ./on_thread.ts import after the ../ imports to match the file's order. The readPlacement mutable global is mutated by tests and never restored on failure; use try/finally, or restore it in afterAll in every file that sets it.

    No UI or docs change was needed, so I found nothing to add for the terminal door or docs/features/.

  • Checks look

    look green — its preview answered, ready for a look deploy 0b749de

    Check passeddeploy 0b749de

    Website spec: 25 findings (report only)
  • History 2 steps

This pull asks for more cpus. Its preview and check run at the size main declares; the larger size applies when the pull lands.

opened this

Phase D1 of #16840 (hosting at every scale). Memory per awake forge sets how many forges a machine holds.

Measured on a fresh forge (macOS arm64, Bun 1.4.4): idle 396 → 210 MB, after 150 requests 400 → 218 MB, idle CPU 1.3% → 0.5%. Cold start is unchanged.

Where it went: the pages and lanes Workers started at boot each loaded about 2,458 modules (around 100 MB each). The new src/flow/on_thread.ts reads each kind of picture on the forge's thread through the worker's own code path. The first reading over 50 ms moves that kind to its worker for the rest of the process. So a small forge never starts them, and a big one moves after one slow reading.

test/idle-memory.test.ts boots main.ts and holds the idle RSS under a budget (350 MB on darwin, 480 MB on linux, to be lowered once a Linux runner reports).

🤖 Generated with Claude Code

4 earlier comments
commented

Taken over by @trevato; stopped @sentinel.

commented

Given back to the crew: a reviewer asked for changes and no one answered for a day, so the builder takes it again.

commented

Parked, offered to the crew again: it sat 6 h with no push, and nobody on the crew can take it from here (a person's branch: no builder can push it), so it waits for its author. The last verdict (changes requested): The idea is right: a small forge shouldn't pay about 100 MB for each of two idle workers. I'm requesting changes on tests and on one lock-up risk. I didn't change or run anything. 1. The new placement wiring has no test. test/idle-memory.test.ts unit-tests on_thread.ts, but nothing covers t… (The forge posts this; nobody wrote it by hand.)

commented

Given back to the crew: a reviewer asked for changes and no one answered for a day, so the builder takes it again.

commented

Answered for #17832, left as it is.

State: changes requested: juniper's notes on src/flow/lanes.ts and src/flow/pages.ts (untested branches, a first read that blocks).

Why not finished: this pull is trevato's own, a person's branch. #17832 lets a builder rebase, fix or apply reviews only on the crew's own pulls, so the crew does not push here. To hand it to the crew, give it back (or open an issue that names it), and a builder takes it from there. Nothing was merged or closed.

Sign in to join this conversation.

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

Keyboard shortcuts

Docs