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

Revert #17320: the bundle boot's CPU share doesn't separate bundle from source on Linux #17346

opened this

Merged 31h 21m ago, live in production

revert/17320 → main 0 commits

  • Merged. revert/17320 was merged into main as 2e737a7.

Review

Sign in to review this change.
3 files changed +26 −51
docs/features/bundle.md +1 −1
@@ -8,4 +8,4 @@ row: Boot the forge from a bundle
88
99 Spawn to `/readyz` is 1.3-1.55 s against 3.8-4.4 s for `bun src/main.ts`, because the loader skips 3,985 modules. No dependency is added.
1010
11 `test/bundle-workers.test.ts` loads each worker from the bundle; `test/bundle-boot-time.test.ts` boots the bundle and the source in the same run and holds the bundle to a share of the source boot's CPU to ready, so a busy machine slows neither side against the other; its header has the measured shares and the bound. `forge.json` `run` and the release swap still boot the source: that is the owner's call (#17019).
11 `test/bundle-workers.test.ts` loads each worker from the bundle; `test/bundle-boot-time.test.ts` holds the boot to 1.5 s with a stated 3x margin for a loaded box. `forge.json` `run` and the release swap still boot the source: that is the owner's call (#17019).
scripts/gate.ts +1 −1
@@ -55,7 +55,7 @@ export const SLOW: readonly Exclusion[] = [
5555 { file: "test/shared-density.test.ts", reason: "spawns a fresh bun child that loads the whole app and makes forges to read its own RSS; 2 s alone, 2.3 s a test under full-suite load", issue: 16857 },
5656 { file: "test/bundle-boot.test.ts", reason: "bundles src/main.ts with bun build --minify and boots the one file with no source beside it; 2.6 s a test under full-suite load", issue: 16853 },
5757 { file: "test/bundle-workers.test.ts", reason: "bundles src/main.ts and every worker, then loads each worker from the bundle; 4 s a test under full-suite load", issue: 17019 },
58 { file: "test/bundle-boot-time.test.ts", reason: "bundles src/main.ts and boots it and the source three times each on an empty directory, for their CPU to /readyz; 6 s a test alone", issue: 17019 },
58 { file: "test/bundle-boot-time.test.ts", reason: "bundles src/main.ts and boots it up to three times on an empty directory to time spawn to /readyz; 5 s a test alone", issue: 17019 },
5959 { file: "test/boot-idle-memory.test.ts", reason: "boots the real src/main.ts and waits real seconds for its RSS to settle; 8.6 s a test", issue: 16851 },
6060 { file: "test/boot-lazy.test.ts", reason: "imports the whole MCP module and its tools to compare their routes with the lazy list; 2.2 s alone, 2.5 s under full-suite load", issue: 17021 },
6161 { file: "test/landsim.test.ts", reason: "runs seeded landing simulations over real repositories and queues; 16 s a file alone, 28.8 s and 2.8 s a test under full-suite load", issue: 13765 },
test/bundle-boot-time.test.ts +24 −49
@@ -1,15 +1,12 @@
11 /**
2 * The boot the forge can run, the bundle, is the cheap path to `/readyz` 200 on an empty data
3 * directory (#17019): source `bun src/main.ts` spends its boot loading modules, and the bundle
4 * does not. Measured as CPU from spawn to ready, the bundle's against the source boot's in the same
5 * run: a busy runner's waits count against neither, so it fails only if the bundle starts paying
6 * what the source does. It was a wall-clock bound (4.5 s), red on loaded runners (2026-12-01:
7 * 4804, 5372, 5158 ms on #17277).
2 * The boot the forge can run, the bundle, goes from spawn to `/readyz` 200 on an empty data
3 * directory under 1.5 s (#17019). Source `bun src/main.ts` takes 3.8-4.4 s of module loading on the
4 * crew box; the bundle 1.3-1.55 s.
85 *
9 * SHARE: measured on the Mac, the bundle took 0.37 and 0.39 of the source boot's CPU (645-870 ms
10 * against 1721-1985 ms); the bound is 0.6, half again over that. With a source module tree
11 * imported at the bundle's top for one run (src/http/server.ts), the share was 0.94: red. The
12 * numbers are in the failure message.
6 * The margin: the gate box runs many shards at once, and the measure was on a loaded box too, so
7 * the test holds the boot to BUDGET_MS x MARGIN (4.5 s): still well under the source boot, so it
8 * fails if the bundle stops being the cheap path. Up to three boots, the fastest counts, since a
9 * stall on a loaded box is not the bundle's. The times are in the failure message.
1310 *
1411 * @tree-scan: boots all of src/ through a bundle of main.ts.
1512 */
@@ -23,66 +20,44 @@ import { collectOutput } from "./helpers/collect-output.ts";
2320 import { waitFor } from "./helpers/poll.ts";
2421 import { productionEnv } from "./helpers/production-env.ts";
2522
26 /**
27 * The most of the source boot's CPU to ready the bundle may spend, measured in the same run (the
28 * file's note says how it was chosen).
29 */
30 export const SHARE = 0.6;
31 const TRIES = 3; // each side's fewest CPU of a few: one boot can catch a collection the other did not
23 export const BUDGET_MS = 1500;
24 export const MARGIN = 3;
25 const TRIES = 3; // a loaded box stalls one boot; the fastest of a few shows the bundle
3226
3327 const root = mkdtempSync(join(tmpdir(), "forge-bundle-time-"));
3428 afterAll(() => rmSync(root, { recursive: true, force: true }));
35 const SOURCE = join(import.meta.dir, "..", "src", "main.ts");
3629
37 /** One boot of `main`: the CPU (user + system, ms) it spent from spawn to `/readyz` 200. */
30 /** One boot: ms from spawn to `/readyz` 200, on a fresh empty data directory. */
3831 async function boot(main: string, n: number): Promise<number> {
39 const dir = join(root, `run${n}-${main === SOURCE ? "source" : "bundle"}`);
32 const dir = join(root, `run${n}`);
4033 mkdirSync(join(dir, "data"), { recursive: true });
4134 const caFile = join(dir, "ca.crt");
4235 writeFileSync(caFile, "-----BEGIN CERTIFICATE-----\nMIIBfake\n-----END CERTIFICATE-----\n");
4336 const port = await freePort();
4437 const env: Record<string, string> = { PATH: process.env["PATH"] ?? "", ...productionEnv({ dataDir: join(dir, "data"), port, sshPort: await freePort(), caFile }) };
4538 for (const key of ["HOME", "TMPDIR", "FORGE_CELLS", "FORGE_TEST_SOCKET"]) if (process.env[key]) env[key] = process.env[key]!;
39 const t0 = performance.now();
4640 const child = Bun.spawn([process.execPath, main], { cwd: dir, env, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
4741 const out = { text: "" };
4842 const reading = collectOutput(out, child.stdout, child.stderr);
49 let status = 0;
5043 try {
51 // Asked until it answers or exits: the readiness is the event; no clock bounds it here.
52 await waitFor(
53 async () => {
54 status = await fetch(`http://127.0.0.1:${port}/readyz`).then((r) => r.status, () => 0);
55 return status === 200 || child.exitCode !== null;
56 },
57 { every: 25, within: 120_000 },
58 );
44 let status = 0;
45 while (status !== 200 && child.exitCode === null && performance.now() - t0 < 60_000) {
46 status = await fetch(`http://127.0.0.1:${port}/readyz`).then((r) => r.status, () => 0);
47 if (status !== 200) await waitFor(() => false, { every: 25, within: 25 });
48 }
5949 expect(status, out.text.slice(-1500)).toBe(200);
50 return performance.now() - t0;
6051 } finally {
6152 child.kill("SIGKILL");
6253 await child.exited;
6354 await reading;
6455 }
65 // CPU, not wall: a busy runner's queueing for a core counts against neither side.
66 const used = child.resourceUsage();
67 if (used === undefined) throw new Error("no resource usage for the boot");
68 return Number(used.cpuTime.total) / 1000;
6956 }
7057
71 // The bundle is the cheap path (#17019): source `bun src/main.ts` spends its boot loading modules,
72 // and the bundle does not. Both are booted here, on the same machine in the same run, and each
73 // side's fewest CPU to ready is compared, so it fails if the bundle starts paying what the source
74 // does, and not because the runner is busy.
75 test(`the bundle reaches /readyz on under ${SHARE * 100}% of the source boot's CPU (fewest of ${TRIES} each)`, async () => {
58 test(`the bundle answers /readyz 200 within ${BUDGET_MS} ms x ${MARGIN} of spawn (fastest of ${TRIES})`, async () => {
7659 const main = bundle(join(root, "out"));
77 const bundled: number[] = [];
78 const source: number[] = [];
79 for (let n = 0; n < TRIES; n++) {
80 bundled.push(await boot(main, n));
81 source.push(await boot(SOURCE, n));
82 }
83 const share = Math.min(...bundled) / Math.min(...source);
84 const said = `CPU to ready: bundle ${bundled.map(Math.round).join(", ")} ms; source ${source.map(Math.round).join(", ")} ms; share ${share.toFixed(2)}`;
85 // Every run says its share, so each check's log carries the number its machine measured.
86 console.log(said);
87 expect(share, said).toBeLessThan(SHARE);
88 }, 240_000);
60 const took: number[] = [];
61 for (let n = 0; n < TRIES && !(Math.min(...took) < BUDGET_MS * MARGIN); n++) took.push(await boot(main, n));
62 expect(Math.min(...took), `spawn to /readyz 200 took ${took.map(Math.round).join(", ")} ms`).toBeLessThan(BUDGET_MS * MARGIN);
63 }, 180_000);

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

Keyboard shortcuts

Docs