Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Worker: the desktop's live GPU share never counts as another program

Adarsh795fa9a0497f
diff --git a/bin/lib/worker/local-work.mjs b/bin/lib/worker/local-work.mjs
index 1ce29dc1..3ae5963f 100644
--- a/bin/lib/worker/local-work.mjs
+++ b/bin/lib/worker/local-work.mjs
@@ -10,7 +10,7 @@
// and anything else as another program.
//
// Others = the GPU's total used memory, minus the worker's own ComfyUI, minus local ComfyUI work, minus the desktop's
-// usual share (measured at setup).
+// share (measured at setup, or what the desktop's processes hold now when that is more).
//
// One exception, for the owner's own jobs, which ask local ComfyUI work for no turn: local ComfyUI work that holds the
// GPU's memory is asked whether it runs anything (its /queue, read only). When it runs nothing and has nothing queued,
@@ -169,7 +169,8 @@ export function unknownHolder(counters, listing, ownPid, minMb) {
* `who` names the biggest other program (for the busy pause). `source`: "counters", "lock" (the counters failed, the
* lock decided) or "total" (neither: everything that isn't the worker's own counts as another program, which fails
* safe). `o`: { usedMb, apps (nvidia-smi's, for names), counters, listing, own: { pid, port, running, mb }, ports,
- * excludePorts, excludePids, baselineMb, lock (readLock's), lockOwners, gpu }.
+ * excludePorts, excludePids, baselineMb, liveDesktop (false: the setup measurement, which counts the desktop itself),
+ * lock (readLock's), lockOwners, gpu }.
*/
export function splitMemory(o) {
const base = Math.max(0, Number(o.baselineMb) || 0);
@@ -184,8 +185,12 @@ export function splitMemory(o) {
// Its own ComfyUI before the counters list it: what torch says, as before.
const ownMb = counted > 0 ? counted : fallbackMb;
const workMb = sum(new Set(work.keys()));
- const othersMb = Math.max(0, o.usedMb - ownMb - workMb - base);
const nameOf = (pid) => o.listing.names?.[pid] ?? o.apps?.find((a) => a.pid === pid)?.name ?? null;
+ // The desktop as it is now (the compositor, browsers, editors, a remote-desktop session): what its processes hold,
+ // when that is more than the share measured at setup. A remote session can grow the compositor past 1 GB; that never
+ // makes the GPU busy for a job.
+ const desktopMb = mine.filter((c) => !own.has(c.pid) && !work.has(c.pid) && isDesktop(nameOf(c.pid))).reduce((n, c) => n + c.mb, 0);
+ const othersMb = Math.max(0, o.usedMb - ownMb - workMb - (o.liveDesktop === false ? base : Math.max(base, desktopMb)));
const top = mine.filter((c) => !own.has(c.pid) && !work.has(c.pid) && c.mb > 0 && !isDesktop(nameOf(c.pid))).sort((a, b) => b.mb - a.mb)[0];
const who = (top && nameOf(top.pid)) ?? "another program";
const firstPort = [...work.values()][0] ?? null;
@@ -260,7 +265,7 @@ export async function measureBaseline(cfg, deps = {}) {
const mine = cfg.workDir ? ownComfyOf(cfg.workDir) : null;
const own = { pid: mine?.pid ?? null, port: mine?.port ?? null, running: false, mb: null };
const o = { ports: cfg.localComfyPorts, excludePorts: cfg.localComfyExcludePorts, excludePids: cfg.localComfyExcludePids };
- const split = splitMemory({ usedMb: reading.usedMb, apps: reading.apps, counters, listing, own, ...o, baselineMb: 0, gpu: cfg.gpuLuid });
+ const split = splitMemory({ usedMb: reading.usedMb, apps: reading.apps, counters, listing, own, ...o, baselineMb: 0, liveDesktop: false, gpu: cfg.gpuLuid });
// The rest, by process, for the owner to see what was counted.
const pids = workPids(listing, { ...o, ownPid: own.pid, ownPort: own.port });
const gpu = pickGpu(counters, cfg.gpuLuid);
diff --git a/tests/worker-turns.test.ts b/tests/worker-turns.test.ts
index e649fb8c..c9c2341b 100644
--- a/tests/worker-turns.test.ts
+++ b/tests/worker-turns.test.ts
@@ -120,12 +120,24 @@ describe("the port table and the GPU counters", () => {
it("never names a desktop process as the cause: the biggest other one, else another program", () => {
const names = { ...LISTING, names: { ...LISTING.names, "77": "dwm", "78": "msedge", "5555": "game" } };
const desktopOnly = splitMemory({ usedMb: 9000, counters: parseCounters(typeperf([[77, 1500], [78, 900]])), listing: names, own: { pid: null, port: null, running: false, mb: null }, ports: [8188, 8199], baselineMb: 600 });
- expect(desktopOnly).toMatchObject({ othersMb: 8400, who: "another program" });
+ // what the desktop's processes hold now (2400 MB) counts as the desktop, not the 600 MB measured at setup
+ expect(desktopOnly).toMatchObject({ othersMb: 6600, who: "another program" });
expect(splitMemory({ usedMb: 9000, counters: parseCounters(typeperf([[77, 3000], [5555, 2000]])), listing: names, own: { pid: null, port: null, running: false, mb: null }, ports: [8188, 8199], baselineMb: 600 }).who).toBe("game");
const apps = [{ pid: 12092, name: "ShellHost.exe", usedMb: null }, { pid: 5, name: "blender.exe", usedMb: null }];
expect(splitMemory({ usedMb: 9000, counters: null, listing: null, apps, own: { pid: null, port: null, running: false, mb: null }, baselineMb: 600, lock: null }).who).toBe("blender.exe");
});
+ it("a remote-desktop session grows the compositor past the busy line: the GPU isn't busy for that", () => {
+ const names = { ...LISTING, names: { ...LISTING.names, "77": "dwm", "78": "msedge", "79": "Code", "80": "Notepad" } };
+ const counters = parseCounters(typeperf([[77, 1563], [78, 281], [79, 252], [80, 40]]));
+ const s = splitMemory({ usedMb: 2250, counters, listing: names, own: { pid: null, port: null, running: false, mb: null }, ports: [8188, 8199], baselineMb: 700 });
+ expect(s.othersMb).toBeLessThan(1024);
+ // a real program next to it still counts
+ const game = splitMemory({ usedMb: 8250, counters: parseCounters(typeperf([[77, 1563], [5555, 6000]])), listing: { ...names, names: { ...names.names, "5555": "game" } }, own: { pid: null, port: null, running: false, mb: null }, ports: [8188, 8199], baselineMb: 700 });
+ expect(game.othersMb).toBeGreaterThan(5000);
+ expect(game.who).toBe("game");
+ });
+
it("its own ComfyUI's share is sure only when read per process (the counters), not from torch alone", () => {
const own = { pid: 900, port: 31337, running: true, mb: 1400 };
expect(splitMemory({ usedMb: 23_000, counters: parseCounters(typeperf([[900, 21_000]])), listing: LISTING, own, ports: [8188, 8199], baselineMb: 600 })).toMatchObject({ ownMb: 21_000, ownSure: true, othersMb: 1400 });