The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Workers: a lane may take shorter clips of larger frames
Adarshcbd7e21e34c4
diff --git a/src/components/workers-admin.tsx b/src/components/workers-admin.tsxindex 78121428..be737cfa 100644--- a/src/components/workers-admin.tsx+++ b/src/components/workers-admin.tsx@@ -25,8 +25,11 @@ import { cn } from "@/lib/utils";type Hours = { always: true } | { tz: string; days: Record<string, [string, string][]> };-/** A lane a worker may run: how long a job waits before it takes it, and the longest clip it takes there (none: no limit). */-type LaneAllow = { delayMs: number; maxSeconds?: number };+/**+ * A lane a worker may run: how long a job waits before it takes it, the longest clip it takes there (none: no limit),+ * and a shorter longest clip for frames larger than `bigFrom` megapixels.+ */+type LaneAllow = { delayMs: number; maxSeconds?: number; bigFrom?: number; bigMaxSeconds?: number };interface WorkerView {id: string;@@ -198,8 +201,35 @@ export function allowAllItCanRun(w: LaneSource, allow: Record<string, LaneAllow>const FIT_RANK = { all: 0, some: 1, none: 2 } as const;+/** A small number box that keeps what is typed ("0.", "0.5") and reports a number past 0, or undefined. */+function NumberBox({ value, onValue, label, placeholder }: { value?: number; onValue: (n: number | undefined) => void; label: string; placeholder: string }) {+ const [text, setText] = useState(value ? String(value) : "");+ return (+ <Input+ aria-label={label}+ className="h-7 w-14"+ inputMode="decimal"+ placeholder={placeholder}+ value={text}+ onChange={(e) => {+ setText(e.target.value);+ const n = Number(e.target.value);+ onValue(e.target.value.trim() && Number.isFinite(n) && n > 0 ? n : undefined);+ }}+ />+ );+}+export function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]; onSave: (allow: Record<string, LaneAllow>) => void }) {const [allow, setAllow] = useState(w.allow);+ // The large-frame limit: a number past 0 sets each half, anything else clears it (both are needed to take effect).+ const setLimit = (lane: string, k: "maxSeconds" | "bigFrom" | "bigMaxSeconds", v: number | undefined) =>+ setAllow((was) => {+ const next: LaneAllow = { ...(was[lane] ?? { delayMs: 0 }) };+ if (v) next[k] = v;+ else delete next[k];+ return { ...was, [lane]: next };+ });// Every workflow first, then some of them, then none; by name within each.const sorted = [...lanes].sort((a, b) => FIT_RANK[laneFit(w, a.lane).kind] - FIT_RANK[laneFit(w, b.lane).kind] || a.label.localeCompare(b.label));const runnable = runnableLanes(w).length;@@ -254,22 +284,15 @@ export function LanesEditor({ w, lanes, onSave }: { w: WorkerView; lanes: Lane[]</label>)}{l.lane in allow && (- <label className="flex items-center gap-1 text-[12px] text-muted-foreground">+ <span className="flex flex-wrap items-center gap-1 text-[12px] text-muted-foreground">clips up to- <Input- aria-label={`Longest clip for ${l.label}`}- className="h-7 w-14"- inputMode="decimal"- placeholder="any"- value={allow[l.lane]?.maxSeconds ? String(allow[l.lane]!.maxSeconds) : ""}- onChange={(e) => {- const most = Number(e.target.value);- const { maxSeconds: _was, ...rest } = allow[l.lane] ?? { delayMs: 0 };- setAllow({ ...allow, [l.lane]: { ...rest, ...(Number.isFinite(most) && most > 0 && { maxSeconds: most }) } });- }}- />+ <NumberBox label={`Longest clip for ${l.label}`} placeholder="any" value={allow[l.lane]?.maxSeconds} onValue={(n) => setLimit(l.lane, "maxSeconds", n)} />+ s, above+ <NumberBox label={`Frame size for shorter clips on ${l.label}`} placeholder="MP" value={allow[l.lane]?.bigFrom} onValue={(n) => setLimit(l.lane, "bigFrom", n)} />+ MP up to+ <NumberBox label={`Longest clip of larger frames for ${l.label}`} placeholder="any" value={allow[l.lane]?.bigMaxSeconds} onValue={(n) => setLimit(l.lane, "bigMaxSeconds", n)} />s- </label>+ </span>)}</li>);diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex 502203ea..150d906c 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -173,12 +173,23 @@ interface Allow {delayMs: number;/** The longest clip this worker takes in this lane, in seconds (none: as long as its PC's ceiling allows). */maxSeconds?: number;+ /** Frames larger than this many megapixels... */+ bigFrom?: number;+ /** ...are taken in clips up to this many seconds (a 720p clip may be shorter than a 480p one). */+ bigMaxSeconds?: number;}const allowOf = (w: WorkerRow) => json<Record<string, Allow>>(w.allow_json, {});-/** Is the job longer than this worker takes in its lane (the lane's own clip limit)? */-const pastLaneLimit = (allow: Record<string, Allow>, lane: string, size?: { seconds?: number } | null) => {- const most = allow[lane]?.maxSeconds;+/** The longest clip a lane's own limits let a worker take at this frame size (undefined: no limit of the lane's own). */+const laneMostSeconds = (a: Allow | undefined, megapixels?: number): number | undefined => {+ if (!a) return undefined;+ const big = a.bigFrom && a.bigMaxSeconds && (megapixels ?? 0) > a.bigFrom + 1e-9 ? a.bigMaxSeconds : undefined;+ const limits = [a.maxSeconds, big].filter((x): x is number => !!x);+ return limits.length ? Math.min(...limits) : undefined;+};+/** Is the job longer than this worker takes in its lane at its frame size (the lane's own clip limits)? */+const pastLaneLimit = (allow: Record<string, Allow>, lane: string, size?: { seconds?: number; megapixels?: number } | null) => {+ const most = laneMostSeconds(allow[lane], size?.megapixels);return !!most && (size?.seconds ?? 0) > most + 1e-9;};/** The lanes and workflows its files let it run, and the requirements index they were worked out with (none: an older row). */@@ -1854,12 +1865,12 @@ export function workersHold(workflowId: string): boolean {* The largest job of a workflow any worker that may and can run it makes (its PC's ceiling), each limit apart: undefined* where one of them has no limit, and for a workflow none of them runs. Said before Run with a size they don't make.*/-export function workersMost(workflowId: string): { maxMegapixels?: number; maxSeconds?: number; maxOutputs?: number } {+export function workersMost(workflowId: string, size?: { megapixels?: number }): { maxMegapixels?: number; maxSeconds?: number; maxOutputs?: number } {const lane = poolLane(workflowId);- // Each worker's PC ceiling, its longest clip narrowed to its lane's own limit when it has one.+ // Each worker's PC ceiling, its longest clip narrowed to its lane's own limit (at this frame size) when it has one.const ceilings = ableWorkers(workflowId).map((w): Ceiling | null => {const c = ceilingOf(w);- const laneMost = allowOf(w)[lane]?.maxSeconds;+ const laneMost = laneMostSeconds(allowOf(w)[lane], size?.megapixels);if (!laneMost) return c;return { ...c, maxSeconds: c?.maxSeconds ? Math.min(c.maxSeconds, laneMost) : laneMost };});@@ -2537,9 +2548,13 @@ export function patchWorker(id: string, p: WorkerPatch, now = Date.now(), by = "if (!/^[0-9a-f]{12}$|^small$/.test(lane)) throw new Error(`No such lane: ${lane}`);const delay = Number((v as { delayMs?: unknown })?.delayMs ?? 0);const most = Number((v as { maxSeconds?: unknown })?.maxSeconds ?? 0);+ const bigFrom = Number((v as { bigFrom?: unknown })?.bigFrom ?? 0);+ const bigMost = Number((v as { bigMaxSeconds?: unknown })?.bigMaxSeconds ?? 0);+ const pos = (n: number) => Number.isFinite(n) && n > 0;allow[lane] = {delayMs: Number.isFinite(delay) && delay >= 0 ? Math.min(delay, 24 * 3_600_000) : 0,- ...(Number.isFinite(most) && most > 0 && { maxSeconds: Math.min(most, 86_400) }),+ ...(pos(most) && { maxSeconds: Math.min(most, 86_400) }),+ ...(pos(bigFrom) && pos(bigMost) && { bigFrom: Math.min(bigFrom, 10_000), bigMaxSeconds: Math.min(bigMost, 86_400) }),};}set.allow_json = JSON.stringify(allow);diff --git a/src/server/hosted.ts b/src/server/hosted.tsindex 471f0384..75be1f4c 100644--- a/src/server/hosted.ts+++ b/src/server/hosted.ts@@ -131,7 +131,7 @@ const tenth = (n: number) => Math.round(n * 10) / 10;/** The largest size the GPUs here make of the limit a job passes, in words ("8 megapixels", "10 s clips"), or null. */export function poolMostWords(endpoint: string | undefined, size: JobSize): string | null {if (!endpoint || endpoint.includes("{")) return null;- const most = workersMost(endpoint);+ const most = workersMost(endpoint, size);if (most.maxMegapixels !== undefined && size.megapixels > most.maxMegapixels) return `${tenth(most.maxMegapixels)} megapixels`;if (most.maxSeconds !== undefined && size.seconds > most.maxSeconds) return `${tenth(most.maxSeconds)} s clips`;if (most.maxOutputs !== undefined && size.outputs > most.maxOutputs) return `${most.maxOutputs} results at a time`;diff --git a/tests/worker-tickets.test.ts b/tests/worker-tickets.test.tsindex f4482249..9927271a 100644--- a/tests/worker-tickets.test.ts+++ b/tests/worker-tickets.test.ts@@ -373,6 +373,30 @@ describe("the line hands out tickets inside each PC's ceiling", () => {expect(pool.workersMost("selftest-image").maxSeconds).toBeUndefined();});+ it("a lane's shorter clip limit for larger frames: 480p runs long, 720p only short, and the most says it per size", async () => {+ const w = addWorker();+ beat(w);+ const allow = Object.fromEntries(Object.entries(pool.workerView(workerRow(w)).allow).map(([l, a]) => [l, l === LANE ? { ...a, maxSeconds: 15.2, bigFrom: 0.5, bigMaxSeconds: 5.2 } : a]));+ pool.patchWorker(w.id, { allow });+ expect(pool.workerView(workerRow(w)).allow[LANE]).toEqual({ delayMs: 0, maxSeconds: 15.2, bigFrom: 0.5, bigMaxSeconds: 5.2 });+ const run = (megapixels: number, seconds: number) => pool.workersCanRun("selftest-image", { size: { megapixels, seconds, outputs: 1 } });+ expect(run(0.41, 15.08)).toBe(true);+ expect(run(0.41, 20)).toBe(false);+ expect(run(0.92, 5.17)).toBe(true);+ expect(run(0.92, 10.13)).toBe(false);+ expect(pool.workersMost("selftest-image").maxSeconds).toBe(15.2);+ expect(pool.workersMost("selftest-image", { megapixels: 0.92 }).maxSeconds).toBe(5.2);+ const mine = await accountTask();+ const needs = JSON.parse(row(mine.id).needs_json!) as { size: { seconds: number; megapixels: number } };+ db().prepare("UPDATE relay_tasks SET needs_json = ? WHERE id = ?").run(JSON.stringify({ ...needs, size: { ...needs.size, megapixels: 0.92, seconds: 10.13 } }), mine.id);+ expect(claim(w)).toBeNull();+ db().prepare("UPDATE relay_tasks SET needs_json = ? WHERE id = ?").run(JSON.stringify({ ...needs, size: { ...needs.size, megapixels: 0.41, seconds: 10.13 } }), mine.id);+ expect(claim(w)?.id).toBe(mine.id);+ // Half of the pair is no limit.+ pool.patchWorker(w.id, { allow: { ...allow, [LANE]: { delayMs: 0, bigFrom: 0.5 } } });+ expect(pool.workerView(workerRow(w)).allow[LANE]).toEqual({ delayMs: 0 });+ });+it("a waiting task whose ticket was made for the catalog before an update gets its ticket made again, with its place kept", async () => {const { noteCatalogProcess, processStart, refreshTickets } = await import("@/server/computer/ticket-refresh");// The app process before the update said its catalog version when it ran.