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
Check · Review · Land · Live — Its check is red.
verify-shards → main 1 commit
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. | ||
| 1857 | 1857 | | `FORGE_CHECKS_DRAIN_S` | `10` | seconds a roll lets running checks finish first | |
| 1858 | 1858 | | `FORGE_CREW_DRAIN_S` | `10` | seconds a roll lets crew runs finish before they are queued again | |
| 1859 | 1859 | | `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) | | |
| 1860 | 1861 | | `FORGE_CHECK_CACHE_DAYS` | `30` | days a package may go unlent before the check install cache drops it | |
| 1861 | 1862 | | `FORGE_CHECK_CACHE_MB` | `2048` | size one repository's check install cache is swept down to | |
| 1862 | 1863 | | `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
src/actions/capacity_effects.ts +2
| @@ -63,6 +63,8 @@ export function effectOf(app: App, key: CapacityKey, value: string): string { | ||
| 63 | 63 | return busy(counts(app, "check")); |
| 64 | 64 | case "checks.shards": |
| 65 | 65 | return `${value} process${value === "1" ? "" : "es"} per check`; |
| 66 | case "checks.verifyShards": | |
| 67 | return `${value} process${value === "1" ? "" : "es"} for main's full check`; | |
| 66 | 68 | case "issue.maxBoxes": |
| 67 | 69 | return `more than ${value} boxes goes to the planner`; |
| 68 | 70 | case "issue.maxChars": |
src/core/capacity.ts +37 −15
| @@ -22,6 +22,7 @@ export type CapacityKey = | ||
| 22 | 22 | | "crew.concurrency" |
| 23 | 23 | | "checks.concurrency" |
| 24 | 24 | | "checks.shards" |
| 25 | | "checks.verifyShards" | |
| 25 | 26 | | "queue.depth" |
| 26 | 27 | | "queue.batch" |
| 27 | 28 | | "week.use" |
| @@ -85,6 +86,15 @@ export const CAPACITY: Record<CapacityKey, Definition> = { | ||
| 85 | 86 | reason: "Shards cut a check's wall time, but each one is another process on the same CPUs.", |
| 86 | 87 | 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.", |
| 87 | 88 | }, |
| 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 | }, | |
| 88 | 98 | "queue.depth": { |
| 89 | 99 | label: "Merge queue candidates at once", |
| 90 | 100 | env: "FORGE_QUEUE_DEPTH", |
| @@ -744,20 +754,29 @@ export function capacityEnv(db: Database, cpus?: number, whole = false): Record< | ||
| 744 | 754 | export type ShardsSource = "setting" | "environment" | "sized"; |
| 745 | 755 | |
| 746 | 756 | /** |
| 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. | |
| 749 | 758 | */ |
| 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"; | |
| 759 | 773 | 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" }; | |
| 761 | 780 | } |
| 762 | 781 | |
| 763 | 782 | /** 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 { | ||
| 782 | 801 | return workerCpus(cpuLimit(), cellCpus); |
| 783 | 802 | } |
| 784 | 803 | |
| 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})`; | |
| 788 | 810 | } |
| 789 | 811 | |
| 790 | 812 | export interface CapacityChange { |
src/web/pages/capacity.ts +1 −1
| @@ -32,7 +32,7 @@ function requireAdmin(ctx: Ctx): Response | undefined { | ||
| 32 | 32 | /** The groups of the table, in order: each a heading and the keys it holds. */ |
| 33 | 33 | const GROUPS: readonly { readonly title: string; readonly keys: readonly CapacityKey[] }[] = [ |
| 34 | 34 | { 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"] }, | |
| 36 | 36 | { |
| 37 | 37 | title: "Hosted forges", |
| 38 | 38 | 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 { | ||
| 23 | 23 | provideCpusForTest, |
| 24 | 24 | setCapacity, |
| 25 | 25 | shardsForCpus, |
| 26 | shardsInForce, | |
| 27 | shardsLine, | |
| 26 | 28 | wholeSuiteShards, |
| 27 | 29 | } from "../src/core/capacity.ts"; |
| 28 | 30 | import { changedOf } from "../src/actions/capacity.ts"; |
| 29 | 31 | import { createUser } from "../src/core/users.ts"; |
| 30 | 32 | |
| 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; | |
| 32 | 34 | const saved = ENV.map((k) => process.env[k]); |
| 33 | 35 | afterEach(() => { |
| 34 | 36 | ENV.forEach((k, i) => { |
| @@ -50,18 +52,55 @@ describe("a run of the whole suite takes more shards than a pull's check", () => | ||
| 50 | 52 | expect(wholeSuiteShards(cpus)).toBe(shards); |
| 51 | 53 | }); |
| 52 | 54 | |
| 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 () => { | |
| 54 | 56 | const dataDir = await mkdtemp(join(tmpdir(), "forge-capacity-whole-")); |
| 55 | 57 | const app = createApp({ dataDir, port: 0 }); |
| 56 | 58 | try { |
| 57 | 59 | delete process.env.FORGE_CHECK_SHARDS; |
| 60 | delete process.env.FORGE_VERIFY_SHARDS; | |
| 58 | 61 | expect(capacityEnv(app.db, 12)).toEqual({ FORGE_CHECK_SHARDS: "4" }); |
| 59 | 62 | expect(capacityEnv(app.db, 12, true)).toEqual({ FORGE_CHECK_SHARDS: "8" }); |
| 60 | 63 | 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)"); | |
| 63 | 103 | } finally { |
| 64 | delete process.env.FORGE_CHECK_SHARDS; | |
| 65 | 104 | app.close(); |
| 66 | 105 | await rm(dataDir, { recursive: true, force: true }); |
| 67 | 106 | } |
test/capacity-first-view.test.ts +6 −5
| @@ -58,16 +58,17 @@ function words(page: string): number { | ||
| 58 | 58 | return text.split(/\s+/).filter((w) => w !== "").length; |
| 59 | 59 | } |
| 60 | 60 | |
| 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 () => { | |
| 62 | 62 | 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. | |
| 64 | 65 | 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); | |
| 66 | 67 | expect(words(page)).toBeLessThan(800); |
| 67 | 68 | const rows = [...page.matchAll(/<tr data-key="([^"]+)">/g)].map((m) => m[1]); |
| 68 | expect(rows.length).toBe(20); | |
| 69 | expect(rows.length).toBe(21); | |
| 69 | 70 | // 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); | |
| 71 | 72 | expect(page).not.toMatch(/<details[^>]*\sopen/); |
| 72 | 73 | expect(page).toContain("running"); |
| 73 | 74 | expect(page).toContain("queued"); |
test/capacity.test.ts +3 −3
| @@ -292,7 +292,7 @@ describe("capacity: only a forge admin reads or changes it", () => { | ||
| 292 | 292 | expect(capacityEnv(app.db)).toEqual({ FORGE_CHECK_SHARDS: "3" }); |
| 293 | 293 | // The check log names the count and its source (#14844): the setting wins over the |
| 294 | 294 | // 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)"); | |
| 296 | 296 | |
| 297 | 297 | const put = await api( |
| 298 | 298 | aliceAdmin, |
| @@ -351,9 +351,9 @@ describe("capacity: only a forge admin reads or changes it", () => { | ||
| 351 | 351 | try { |
| 352 | 352 | expect(capacityEnv(app.db, 80)).toEqual({ FORGE_CHECK_SHARDS: "4" }); |
| 353 | 353 | 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)"); | |
| 355 | 355 | 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" }); | |
| 357 | 357 | } finally { |
| 358 | 358 | if (fromEnv === undefined) delete process.env.FORGE_CHECK_SHARDS; |
| 359 | 359 | else process.env.FORGE_CHECK_SHARDS = fromEnv; |
test/checks-placement.test.ts +1 −1
| @@ -362,7 +362,7 @@ describe("checks placed", () => { | ||
| 362 | 362 | expect(run.state).toBe("ok"); |
| 363 | 363 | expect(run.placement).toBe("process"); |
| 364 | 364 | 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)"); | |
| 366 | 366 | expect(log).toContain("sharded-here"); |
| 367 | 367 | } finally { |
| 368 | 368 | 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", () => { | ||
| 576 | 576 | expect(run.state).toBe("ok"); |
| 577 | 577 | expect(run.placement).toBe("runner"); |
| 578 | 578 | const log = logOf(run.id); |
| 579 | expect(log).toContain("3 shards (setting)"); | |
| 579 | expect(log).toContain("3 shards (checks.shards setting)"); | |
| 580 | 580 | expect(log).toContain("ran-on-sharded"); |
| 581 | 581 | expect(log).not.toContain("running here"); |
| 582 | 582 | } finally { |
| @@ -605,7 +605,7 @@ describe("a pull's check with FORGE_CHECKS_PLACEMENT=runner", () => { | ||
| 605 | 605 | const run = await f.settled((r) => r.commitOid === oid, 30_000); |
| 606 | 606 | expect(run.state).toBe("ok"); |
| 607 | 607 | 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)`); | |
| 609 | 609 | } finally { |
| 610 | 610 | if (fromEnv === undefined) delete process.env.FORGE_CHECK_SHARDS; |
| 611 | 611 | else process.env.FORGE_CHECK_SHARDS = fromEnv; |
new above
offline