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

Main's full check gets its own shard count (default 8): about 43 → 21 min #16723

opened this

Check · Review · Land · Live — Its check is red. Next: builder, its check is red.

Ready to land

verify-shards → main 1 commit

Review

Sign in to review this change.
10 files changed +98 −32
docs/APPS.md +1
@@ -1857,6 +1857,7 @@ a link to the milestone (`docs/PLANNING.md`); its progress never does.
18571857 | `FORGE_CHECKS_DRAIN_S` | `10` | seconds a roll lets running checks finish first |
18581858 | `FORGE_CREW_DRAIN_S` | `10` | seconds a roll lets crew runs finish before they are queued again |
18591859 | `FORGE_CHECK_SHARDS` | the machine's cores | test shards per check (live: Settings → Capacity) |
1860 | `FORGE_VERIFY_SHARDS` | the cell's CPUs, at most 8 | test shards for main's full check, the verify tier, apart from the above (live: Settings → Capacity) |
18601861 | `FORGE_CHECK_CACHE_DAYS` | `30` | days a package may go unlent before the check install cache drops it |
18611862 | `FORGE_CHECK_CACHE_MB` | `2048` | size one repository's check install cache is swept down to |
18621863 | `FORGE_CELLS_EGRESS` | ignored | logged once at boot; egress is enforced unless an admin sets `cells.egress` (Settings → Capacity), with a reason |
src/actions/capacity.ts +1
@@ -46,6 +46,7 @@ export const SETTABLE_CAPACITY = [
4646 "crew.concurrency",
4747 "checks.concurrency",
4848 "checks.shards",
49 "checks.verifyShards",
4950 "cells.egress",
5051 "cells.servingCores",
5152 "guard_new_accounts",
src/actions/capacity_effects.ts +2
@@ -63,6 +63,8 @@ export function effectOf(app: App, key: CapacityKey, value: string): string {
6363 return busy(counts(app, "check"));
6464 case "checks.shards":
6565 return `${value} process${value === "1" ? "" : "es"} per check`;
66 case "checks.verifyShards":
67 return `${value} process${value === "1" ? "" : "es"} for main's full check`;
6668 case "issue.maxBoxes":
6769 return `more than ${value} boxes goes to the planner`;
6870 case "issue.maxChars":
src/core/capacity.ts +37 −15
@@ -22,6 +22,7 @@ export type CapacityKey =
2222 | "crew.concurrency"
2323 | "checks.concurrency"
2424 | "checks.shards"
25 | "checks.verifyShards"
2526 | "queue.depth"
2627 | "queue.batch"
2728 | "week.use"
@@ -85,6 +86,15 @@ export const CAPACITY: Record<CapacityKey, Definition> = {
8586 reason: "Shards cut a check's wall time, but each one is another process on the same CPUs.",
8687 help: "How many parallel shards a check's test run uses (handed to checks and crew shells as FORGE_CHECK_SHARDS). Empty: the pod's CPUs, at most 4 — and, in a check, no more than its cell holds.",
8788 },
89 "checks.verifyShards": {
90 label: "Test shards, main full check",
91 env: "FORGE_VERIFY_SHARDS",
92 kind: { type: "count", min: 1, max: 32 },
93 fallback: "1",
94 sized: (cpus) => wholeSuiteShards(cpus),
95 reason: "Main's full check is ~10,000 s of work; its wall time is that over its shards.",
96 help: "Shards for the verify tier, apart from checks.shards; at most the cell's CPUs. Empty: up to 8. About 9.5 GiB each.",
97 },
8898 "queue.depth": {
8999 label: "Merge queue candidates at once",
90100 env: "FORGE_QUEUE_DEPTH",
@@ -744,20 +754,29 @@ export function capacityEnv(db: Database, cpus?: number, whole = false): Record<
744754 export type ShardsSource = "setting" | "environment" | "sized";
745755
746756 /**
747 * The shard count {@link capacityEnv} hands a check, and where it came from: an admin's value,
748 * else `FORGE_CHECK_SHARDS` in the forge's environment, else sized from `cpus`.
757 * The shard count in force, the setting it was read from, and where that setting's value came from.
749758 */
750 export function shardsInForce(
751 db: Database,
752 cpus?: number,
753 whole = false,
754 ): { count: number; source: ShardsSource } {
755 const stored = storedCapacity(db, "checks.shards");
756 if (stored !== undefined) return { count: Number(stored), source: "setting" };
757 const env = explicitDefault("checks.shards");
758 if (env !== undefined) return { count: Number(env), source: "environment" };
759 export type ShardsInForce = {
760 count: number;
761 key: "checks.shards" | "checks.verifyShards";
762 source: ShardsSource;
763 };
764
765 /**
766 * The shard count {@link capacityEnv} hands a check, and where it came from: an admin's value,
767 * else the setting's variable in the forge's environment, else sized from `cpus`. A pull's check
768 * reads `checks.shards`; a run of the whole suite (`whole`, the verify tier) reads
769 * `checks.verifyShards` alone, held to `cpus`, so the pull's count never sizes it (#16671).
770 */
771 export function shardsInForce(db: Database, cpus?: number, whole = false): ShardsInForce {
772 const key = whole ? "checks.verifyShards" : "checks.shards";
759773 const sized = cpus ?? cpuLimit();
760 return { count: whole ? wholeSuiteShards(sized) : shardsForCpus(sized), source: "sized" };
774 const held = (n: number): number => (whole ? Math.max(1, Math.min(n, Math.floor(sized) || 1)) : n);
775 const stored = storedCapacity(db, key);
776 if (stored !== undefined) return { count: held(Number(stored)), key, source: "setting" };
777 const env = explicitDefault(key);
778 if (env !== undefined) return { count: held(Number(env)), key, source: "environment" };
779 return { count: whole ? wholeSuiteShards(sized) : shardsForCpus(sized), key, source: "sized" };
761780 }
762781
763782 /** Most shards the whole suite takes by default: it runs alone, at the lowest priority (#16655). */
@@ -782,9 +801,12 @@ export function checkShardCpus(cellCpus: number | undefined): number {
782801 return workerCpus(cpuLimit(), cellCpus);
783802 }
784803
785 /** The check log's line for {@link shardsInForce}: `3 shards (setting)`. */
786 export function shardsLine(shards: { count: number; source: ShardsSource }): string {
787 return `${shards.count} shard${shards.count === 1 ? "" : "s"} (${shards.source})`;
804 /**
805 * The check log's line for {@link shardsInForce}, naming the setting it read:
806 * `3 shards (checks.shards setting)`, `8 shards (checks.verifyShards sized)`.
807 */
808 export function shardsLine(shards: ShardsInForce): string {
809 return `${shards.count} shard${shards.count === 1 ? "" : "s"} (${shards.key} ${shards.source})`;
788810 }
789811
790812 export interface CapacityChange {
src/web/pages/capacity.ts +1 −1
@@ -32,7 +32,7 @@ function requireAdmin(ctx: Ctx): Response | undefined {
3232 /** The groups of the table, in order: each a heading and the keys it holds. */
3333 const GROUPS: readonly { readonly title: string; readonly keys: readonly CapacityKey[] }[] = [
3434 { title: "Crew", keys: ["crew.concurrency", "pace.floor", "week.use", "issue.maxBoxes", "issue.maxChars"] },
35 { title: "Checks", keys: ["checks.concurrency", "checks.shards", "queue.batch", "queue.depth", "cells.servingCores"] },
35 { title: "Checks", keys: ["checks.concurrency", "checks.shards", "checks.verifyShards", "queue.batch", "queue.depth", "cells.servingCores"] },
3636 {
3737 title: "Hosted forges",
3838 keys: ["children.max", "children.awake", "children.ownFilesystem", "children.modelEgress", "children.registryEgress", "children.paymentEgress", "children.originEgress"],
test/capacity-cpus.test.ts +44 −5
@@ -23,12 +23,14 @@ import {
2323 provideCpusForTest,
2424 setCapacity,
2525 shardsForCpus,
26 shardsInForce,
27 shardsLine,
2628 wholeSuiteShards,
2729 } from "../src/core/capacity.ts";
2830 import { changedOf } from "../src/actions/capacity.ts";
2931 import { createUser } from "../src/core/users.ts";
3032
31 const ENV = ["FORGE_CHECK_SHARDS", "FORGE_CHECKS_CONCURRENCY"] as const;
33 const ENV = ["FORGE_CHECK_SHARDS", "FORGE_VERIFY_SHARDS", "FORGE_CHECKS_CONCURRENCY"] as const;
3234 const saved = ENV.map((k) => process.env[k]);
3335 afterEach(() => {
3436 ENV.forEach((k, i) => {
@@ -50,18 +52,55 @@ describe("a run of the whole suite takes more shards than a pull's check", () =>
5052 expect(wholeSuiteShards(cpus)).toBe(shards);
5153 });
5254
53 test("the verify tier is told 8 where a pull's check is told 4, and an admin's value wins for both", async () => {
55 test("the verify tier is told 8 where a pull's check is told 4", async () => {
5456 const dataDir = await mkdtemp(join(tmpdir(), "forge-capacity-whole-"));
5557 const app = createApp({ dataDir, port: 0 });
5658 try {
5759 delete process.env.FORGE_CHECK_SHARDS;
60 delete process.env.FORGE_VERIFY_SHARDS;
5861 expect(capacityEnv(app.db, 12)).toEqual({ FORGE_CHECK_SHARDS: "4" });
5962 expect(capacityEnv(app.db, 12, true)).toEqual({ FORGE_CHECK_SHARDS: "8" });
6063 expect(capacityEnv(app.db, 2, true)).toEqual({ FORGE_CHECK_SHARDS: "2" });
61 process.env.FORGE_CHECK_SHARDS = "3";
62 expect(capacityEnv(app.db, 12, true)).toEqual({ FORGE_CHECK_SHARDS: "3" });
64 expect(shardsLine(shardsInForce(app.db, 12, true))).toBe("8 shards (checks.verifyShards sized)");
65 } finally {
66 app.close();
67 await rm(dataDir, { recursive: true, force: true });
68 }
69 });
70
71 test("the verify tier ignores checks.shards, stored or in the environment; a stored checks.verifyShards wins, held to the cell's CPUs (#16671)", async () => {
72 const dataDir = await mkdtemp(join(tmpdir(), "forge-capacity-verify-"));
73 const app = createApp({ dataDir, port: 0 });
74 try {
75 delete process.env.FORGE_VERIFY_SHARDS;
76 const made = await createUser(app.db, {
77 origin: "seed",
78 trusted: true,
79 username: "alice",
80 email: "[email protected]",
81 password: "a-good-passphrase",
82 adminIfFirst: true,
83 });
84 if (!made.ok) throw new Error(made.error);
85 const admin = made.value;
86 // The pull's count, set both ways, as production holds it: the verify tier does not read it.
87 process.env.FORGE_CHECK_SHARDS = "3";
88 setCapacity(app.db, "checks.shards", "4", admin.id);
89 expect(shardsInForce(app.db, 12)).toEqual({ count: 4, key: "checks.shards", source: "setting" });
90 expect(shardsInForce(app.db, 12, true)).toEqual({ count: 8, key: "checks.verifyShards", source: "sized" });
91 // Its own variable is its boot default.
92 process.env.FORGE_VERIFY_SHARDS = "6";
93 expect(shardsInForce(app.db, 12, true)).toEqual({ count: 6, key: "checks.verifyShards", source: "environment" });
94 // A stored value wins over both, and the log line names it.
95 setCapacity(app.db, "checks.verifyShards", "10", admin.id);
96 expect(capacityEnv(app.db, 12, true)).toEqual({ FORGE_CHECK_SHARDS: "10" });
97 expect(shardsLine(shardsInForce(app.db, 12, true))).toBe("10 shards (checks.verifyShards setting)");
98 // Never more than the cell's CPUs.
99 expect(shardsInForce(app.db, 6, true).count).toBe(6);
100 // The pull's check is as it was.
101 expect(capacityEnv(app.db, 12)).toEqual({ FORGE_CHECK_SHARDS: "4" });
102 expect(shardsLine(shardsInForce(app.db, 12))).toBe("4 shards (checks.shards setting)");
63103 } finally {
64 delete process.env.FORGE_CHECK_SHARDS;
65104 app.close();
66105 await rm(dataDir, { recursive: true, force: true });
67106 }
test/capacity-first-view.test.ts +6 −5
@@ -58,16 +58,17 @@ function words(page: string): number {
5858 return text.split(/\s+/).filter((w) => w !== "").length;
5959 }
6060
61 test("the first view: under 800 words and 25 KB with every row folded, every setting beside its live effect", async () => {
61 test("the first view: under 800 words and 26 KB with every row folded, every setting beside its live effect", async () => {
6262 const page = await get();
63 // The page's own part (what the shell around it is not): under 25 KB raw with every fold closed.
63 // The page's own part (what the shell around it is not): under 26 KB raw with every fold closed.
64 // It was 25 KB for 20 rows; the 21st, checks.verifyShards (#16671), costs about 0.8 KB folded.
6465 const main = page.slice(page.indexOf('class="settings-main"'), page.indexOf("</main>"));
65 expect(new TextEncoder().encode(main).length).toBeLessThan(25_000);
66 expect(new TextEncoder().encode(main).length).toBeLessThan(26_000);
6667 expect(words(page)).toBeLessThan(800);
6768 const rows = [...page.matchAll(/<tr data-key="([^"]+)">/g)].map((m) => m[1]);
68 expect(rows.length).toBe(20);
69 expect(rows.length).toBe(21);
6970 // The rest is behind one ⓘ per row, closed.
70 expect(page.match(/<details class="hint why"/g)).toHaveLength(20);
71 expect(page.match(/<details class="hint why"/g)).toHaveLength(21);
7172 expect(page).not.toMatch(/<details[^>]*\sopen/);
7273 expect(page).toContain("running");
7374 expect(page).toContain("queued");
test/capacity.test.ts +3 −3
@@ -292,7 +292,7 @@ describe("capacity: only a forge admin reads or changes it", () => {
292292 expect(capacityEnv(app.db)).toEqual({ FORGE_CHECK_SHARDS: "3" });
293293 // The check log names the count and its source (#14844): the setting wins over the
294294 // environment.
295 expect(shardsLine(shardsInForce(app.db, 80))).toBe("3 shards (setting)");
295 expect(shardsLine(shardsInForce(app.db, 80))).toBe("3 shards (checks.shards setting)");
296296
297297 const put = await api(
298298 aliceAdmin,
@@ -351,9 +351,9 @@ describe("capacity: only a forge admin reads or changes it", () => {
351351 try {
352352 expect(capacityEnv(app.db, 80)).toEqual({ FORGE_CHECK_SHARDS: "4" });
353353 expect(capacityEnv(app.db, 2)).toEqual({ FORGE_CHECK_SHARDS: "2" });
354 expect(shardsLine(shardsInForce(app.db, 1))).toBe("1 shard (sized)");
354 expect(shardsLine(shardsInForce(app.db, 1))).toBe("1 shard (checks.shards sized)");
355355 process.env.FORGE_CHECK_SHARDS = "5";
356 expect(shardsInForce(app.db, 2)).toEqual({ count: 5, source: "environment" });
356 expect(shardsInForce(app.db, 2)).toEqual({ count: 5, key: "checks.shards", source: "environment" });
357357 } finally {
358358 if (fromEnv === undefined) delete process.env.FORGE_CHECK_SHARDS;
359359 else process.env.FORGE_CHECK_SHARDS = fromEnv;
test/checks-placement.test.ts +1 −1
@@ -362,7 +362,7 @@ describe("checks placed", () => {
362362 expect(run.state).toBe("ok");
363363 expect(run.placement).toBe("process");
364364 const log = readRunLog(dataDir, run.id).lines.join("\n");
365 expect(log).toContain("3 shards (setting)");
365 expect(log).toContain("3 shards (checks.shards setting)");
366366 expect(log).toContain("sharded-here");
367367 } finally {
368368 setCapacity(app.db, "checks.shards", null, alice.id);
test/checks-runner-placement.test.ts +2 −2
@@ -576,7 +576,7 @@ describe("a pull's check with FORGE_CHECKS_PLACEMENT=runner", () => {
576576 expect(run.state).toBe("ok");
577577 expect(run.placement).toBe("runner");
578578 const log = logOf(run.id);
579 expect(log).toContain("3 shards (setting)");
579 expect(log).toContain("3 shards (checks.shards setting)");
580580 expect(log).toContain("ran-on-sharded");
581581 expect(log).not.toContain("running here");
582582 } finally {
@@ -605,7 +605,7 @@ describe("a pull's check with FORGE_CHECKS_PLACEMENT=runner", () => {
605605 const run = await f.settled((r) => r.commitOid === oid, 30_000);
606606 expect(run.state).toBe("ok");
607607 expect(run.placement).toBe("runner");
608 expect(logOf(run.id)).toContain(`${sized} shard${sized === 1 ? "" : "s"} (sized)`);
608 expect(logOf(run.id)).toContain(`${sized} shard${sized === 1 ? "" : "s"} (checks.shards sized)`);
609609 } finally {
610610 if (fromEnv === undefined) delete process.env.FORGE_CHECK_SHARDS;
611611 else process.env.FORGE_CHECK_SHARDS = fromEnv;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs