Files
photoreport/apps/api/test/capacity.test.ts
T
1sonhador 1fa97ca3bb
ci / rust (push) Successful in 4m11s
ci / typescript (push) Successful in 7m20s
Keep ZeroZero uploads alive when the worker is busy.
Cap face analysis at what one Node thread can commit, prefer IPv4 so a dead IPv6 route cannot fail the fetch, and leave a photo on the desk when ZeroZero says it is already there. Desktop originals go out one at a time so the app does not freeze on "A enviar…".
2026-10-15 20:14:04 +01:00

41 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { planCapacity, Pressure, type Reading } from "../src/lib/capacity.js";
const GB = 1e9;
describe("capacity", () => {
it("does more at once on a bigger container", () => {
const small = planCapacity({}, { cpus: 4, memoryBytes: 8 * GB });
const big = planCapacity({}, { cpus: 32, memoryBytes: 64 * GB });
expect(small).toMatchObject({ faces: 3, ingest: 4, archive: 2, render: 2, delivery: 4 });
expect(big).toMatchObject({ cpus: 32, faces: 6, ingest: 8, archive: 9, archiveBurst: 91, render: 4, delivery: 8 });
expect(planCapacity({}, { cpus: 48, memoryBytes: 64 * GB })).toMatchObject({ faces: 6, archiveBurst: 91, archiveDownloads: 960 });
// A fixed ARCHIVE_CONCURRENCY never holds a backlog back; downloads run many at once even on a small machine.
expect(planCapacity({ archive: 2 }, { cpus: 4, memoryBytes: 8 * GB })).toMatchObject({ archive: 2, archiveBurst: 7, archiveDownloads: 80 });
});
it("is held back by memory when cores are many and memory is short", () => {
const tight = planCapacity({}, { cpus: 32, memoryBytes: 6 * GB });
expect(tight.faces).toBe(2);
expect(tight.archive).toBe(2);
});
it("keeps what the environment sets", () => {
expect(planCapacity({ faces: 3, archive: 40 }, { cpus: 32, memoryBytes: 64 * GB })).toMatchObject({ faces: 3, archive: 40 });
});
it("lets bulk work step aside while the machine is busy", () => {
const at = (r: Partial<Reading>) => new Pressure(() => ({ cpuStall: null, load: 0, cpus: 32, free: 32 * GB, total: 64 * GB, ...r }));
expect(at({ cpuStall: 5 }).allow(16)).toBe(16);
expect(at({ cpuStall: 45 }).allow(16)).toBe(8);
expect(at({ cpuStall: 80 }).allow(16)).toBe(4);
expect(at({ load: 40 }).allow(16)).toBe(4);
expect(at({ free: 3 * GB }).allow(16)).toBe(4);
expect(at({ cpuStall: 80 }).allow(2)).toBe(1);
// A big backlog: full speed through a saturated CPU, back off only near the limits.
expect(at({ cpuStall: 80 }).allow(36, true)).toBe(36);
expect(at({ cpuStall: 95 }).allow(36, true)).toBe(18);
expect(at({ free: 6 * GB }).allow(36, true)).toBe(18);
});
});