@smoothbricks/nx-plugin 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/dist/.build-inputs.json +11 -5
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +3 -2
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.js +1 -1
- package/dist/executors/bounded-exec/cpu-pool.d.ts +24 -10
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +96 -52
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +98 -45
- package/dist/executors/bounded-exec/host-memory.d.ts +47 -0
- package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.darwin.d.ts +3 -0
- package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.darwin.js +40 -0
- package/dist/executors/bounded-exec/host-memory.js +29 -0
- package/dist/executors/bounded-exec/host-memory.linux.d.ts +14 -0
- package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -0
- package/dist/executors/bounded-exec/host-memory.linux.js +104 -0
- package/dist/executors/bounded-exec/leaf-peak.d.ts +55 -0
- package/dist/executors/bounded-exec/leaf-peak.d.ts.map +1 -0
- package/dist/executors/bounded-exec/leaf-peak.js +146 -0
- package/dist/executors/bounded-exec/peak-waiter.d.ts +2 -0
- package/dist/executors/bounded-exec/peak-waiter.d.ts.map +1 -0
- package/dist/executors/bounded-exec/peak-waiter.js +53 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts +38 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -0
- package/dist/executors/bounded-exec/pool-admission.js +31 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts +6 -4
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +20 -7
- package/dist/executors/bounded-exec/verdict.d.ts +18 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +21 -1
- package/package.json +1 -1
- package/src/executors/bounded-exec/cpu-pool-thread.ts +4 -3
- package/src/executors/bounded-exec/cpu-pool.ts +111 -49
- package/src/executors/bounded-exec/executor.ts +103 -41
- package/src/executors/bounded-exec/host-memory.darwin.ts +44 -0
- package/src/executors/bounded-exec/host-memory.linux.ts +115 -0
- package/src/executors/bounded-exec/host-memory.ts +70 -0
- package/src/executors/bounded-exec/leaf-peak.ts +151 -0
- package/src/executors/bounded-exec/peak-waiter.ts +82 -0
- package/src/executors/bounded-exec/pool-admission.ts +64 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +20 -6
- package/src/executors/bounded-exec/verdict.ts +30 -1
- package/test-timings.json +134 -132
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as _isTypeUint32_1 from "typia/lib/internal/_isTypeUint32";
|
|
2
|
+
import * as _isTypeUint64_1 from "typia/lib/internal/_isTypeUint64";
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import typia from 'typia';
|
|
5
|
+
import { HOST_MEMORY } from './host-memory.js';
|
|
6
|
+
import { resolveOnPath } from './runtime-pin.js';
|
|
7
|
+
/**
|
|
8
|
+
* A leaf's memory peak (specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets itself"; 13_telemetry.md, "Job
|
|
9
|
+
* resource peaks"): the exited command's rusage `ru_maxrss`, which its waiter (`peak-waiter.ts`) reads. The leaf runs
|
|
10
|
+
* no cgroup of its own, even under a cowshed supervisor, whose subtree of the command is an observed fold inside the
|
|
11
|
+
* job's cgroup (07_api.md, `JobSubtreeHandle`), so the peak is the rusage on Linux and macOS alike. The executor writes
|
|
12
|
+
* it into the task's record, and the task's next run is charged it in its run's pool.
|
|
13
|
+
*/
|
|
14
|
+
/** The descriptor the waiter reports on: past the lifecycle channel (3), the subtree admission (4) and mbx's grant (5). */
|
|
15
|
+
export const PEAK_FD = 6;
|
|
16
|
+
/** The waiter's module, in the form this one was loaded in: compiled JavaScript under Nx, TypeScript under Bun. */
|
|
17
|
+
const WAITER = fileURLToPath(new URL(import.meta.url.endsWith('.ts') ? './peak-waiter.ts' : './peak-waiter.js', import.meta.url));
|
|
18
|
+
const isWaiterLine = (() => {
|
|
19
|
+
const _io0 = (input, _exceptionable = true) => "number" === typeof input.started && _isTypeUint32_1._isTypeUint32(input.started) && (1 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
20
|
+
if (["started"].some(prop => key === prop))
|
|
21
|
+
return true;
|
|
22
|
+
const value = input[key];
|
|
23
|
+
if (undefined === value)
|
|
24
|
+
return true;
|
|
25
|
+
return false;
|
|
26
|
+
}));
|
|
27
|
+
const _io1 = (input, _exceptionable = true) => "number" === typeof input.peakBytes && _isTypeUint64_1._isTypeUint64(input.peakBytes) && (1 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
28
|
+
if (["peakBytes"].some(prop => key === prop))
|
|
29
|
+
return true;
|
|
30
|
+
const value = input[key];
|
|
31
|
+
if (undefined === value)
|
|
32
|
+
return true;
|
|
33
|
+
return false;
|
|
34
|
+
}));
|
|
35
|
+
const _io2 = (input, _exceptionable = true) => "string" === typeof input.unmeasured && (1 === Object.keys(input).length || Object.keys(input).every(key => {
|
|
36
|
+
if (["unmeasured"].some(prop => key === prop))
|
|
37
|
+
return true;
|
|
38
|
+
const value = input[key];
|
|
39
|
+
if (undefined === value)
|
|
40
|
+
return true;
|
|
41
|
+
return false;
|
|
42
|
+
}));
|
|
43
|
+
const _iu0 = (input, _exceptionable = true) => (() => {
|
|
44
|
+
if (undefined !== input.started)
|
|
45
|
+
return _io0(input, true && _exceptionable);
|
|
46
|
+
else if (undefined !== input.peakBytes)
|
|
47
|
+
return _io1(input, true && _exceptionable);
|
|
48
|
+
else if (undefined !== input.unmeasured)
|
|
49
|
+
return _io2(input, true && _exceptionable);
|
|
50
|
+
else
|
|
51
|
+
return false;
|
|
52
|
+
})();
|
|
53
|
+
return (input, _exceptionable = true) => "object" === typeof input && null !== input && _iu0(input, true);
|
|
54
|
+
})();
|
|
55
|
+
/**
|
|
56
|
+
* The Bun that runs this executor, else the first `bun` on the executor's own PATH, never one a target's environment
|
|
57
|
+
* names: the waiter is the executor's, not the command's.
|
|
58
|
+
*/
|
|
59
|
+
export function peakWaiter() {
|
|
60
|
+
if (HOST_MEMORY === null) {
|
|
61
|
+
return { kind: 'unmeasured', reason: `${process.platform} has no reader of a leaf's peak` };
|
|
62
|
+
}
|
|
63
|
+
const runtime = process.versions.bun === undefined ? resolveOnPath('bun', process.env.PATH, process.cwd()) : process.execPath;
|
|
64
|
+
return runtime === null
|
|
65
|
+
? { kind: 'unmeasured', reason: 'no bun is on PATH to wait on the command and read its rusage' }
|
|
66
|
+
: { kind: 'waiter', runtime };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The spawn of `file args` under the waiter on `runtime`. `descriptors` are the command's own past stderr, from fd 3:
|
|
70
|
+
* the waiter passes each one that is not ignored at its own number, and takes `PEAK_FD` for its report. The runtime's
|
|
71
|
+
* config is empty, so no preload a workspace's `bunfig.toml` names runs in the waiter.
|
|
72
|
+
*/
|
|
73
|
+
export function underWaiter(runtime, file, args, descriptors) {
|
|
74
|
+
if (descriptors.length > PEAK_FD - 3) {
|
|
75
|
+
throw new RangeError(`a leaf's own descriptors end before ${PEAK_FD}, the waiter's report; it names ${descriptors.length + 3}`);
|
|
76
|
+
}
|
|
77
|
+
const passed = descriptors.flatMap((io, at) => (io === 'ignore' ? [] : [at + 3]));
|
|
78
|
+
const padded = Array.from({ length: PEAK_FD - 3 }, (_, at) => descriptors[at] ?? 'ignore');
|
|
79
|
+
return {
|
|
80
|
+
file: runtime,
|
|
81
|
+
args: ['--config=/dev/null', WAITER, String(PEAK_FD), passed.join(','), file, ...args],
|
|
82
|
+
stdio: ['pipe', 'pipe', 'pipe', ...padded, 'pipe'],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** What the waiter reports on `stream`: the command's pid as it starts it, and the command's peak once it ends. */
|
|
86
|
+
export function readWaiterReport(stream) {
|
|
87
|
+
if (stream === null || stream === undefined) {
|
|
88
|
+
return {
|
|
89
|
+
started: Promise.resolve(null),
|
|
90
|
+
peak: Promise.resolve({ kind: 'unmeasured', reason: 'the waiter was started without its report descriptor' }),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// `Promise.withResolvers` would read better but needs lib es2024; this package inherits lib es2022 from
|
|
94
|
+
// tsconfig.base.json. The report's close names null at the latest.
|
|
95
|
+
let name;
|
|
96
|
+
const started = new Promise((named) => {
|
|
97
|
+
name = named;
|
|
98
|
+
});
|
|
99
|
+
// The waiter's last word: the line after its start, or what was wrong with a line.
|
|
100
|
+
let end = null;
|
|
101
|
+
const line = (text) => {
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(text);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (!(error instanceof SyntaxError))
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
if (!isWaiterLine(parsed)) {
|
|
111
|
+
end = { kind: 'unmeasured', reason: `the waiter reported ${JSON.stringify(text)}, which is no peak` };
|
|
112
|
+
}
|
|
113
|
+
else if ('started' in parsed) {
|
|
114
|
+
name(parsed.started);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
end =
|
|
118
|
+
'peakBytes' in parsed
|
|
119
|
+
? { kind: 'measured', bytes: parsed.peakBytes }
|
|
120
|
+
: { kind: 'unmeasured', reason: parsed.unmeasured };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
let pending = '';
|
|
124
|
+
stream.setEncoding('utf8');
|
|
125
|
+
// eslint-disable-next-line deadline/no-unbounded-wait -- WHY unbounded: the report pipe is the waiter's alone (Bun closes every descriptor it does not pass), so it ends when the waiter does, and the executor's bounds end the waiter
|
|
126
|
+
const peak = new Promise((settle) => {
|
|
127
|
+
stream.on('data', (chunk) => {
|
|
128
|
+
pending += chunk;
|
|
129
|
+
for (let at = pending.indexOf('\n'); at !== -1; at = pending.indexOf('\n')) {
|
|
130
|
+
line(pending.slice(0, at));
|
|
131
|
+
pending = pending.slice(at + 1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
stream.once('error', (error) => {
|
|
135
|
+
name(null);
|
|
136
|
+
settle({ kind: 'unmeasured', reason: `its report descriptor: ${error.message}` });
|
|
137
|
+
});
|
|
138
|
+
stream.once('close', () => {
|
|
139
|
+
if (pending.trim() !== '')
|
|
140
|
+
line(pending.trim());
|
|
141
|
+
name(null);
|
|
142
|
+
settle(end ?? { kind: 'unmeasured', reason: 'the waiter ended before it could report the command' });
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return { started, peak };
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peak-waiter.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/peak-waiter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs';
|
|
2
|
+
import { HOST_MEMORY } from './host-memory.js';
|
|
3
|
+
function isBunSpawner(runtime) {
|
|
4
|
+
return (typeof runtime === 'object' &&
|
|
5
|
+
runtime !== null &&
|
|
6
|
+
'spawn' in runtime &&
|
|
7
|
+
typeof runtime.spawn === 'function' &&
|
|
8
|
+
'version' in runtime &&
|
|
9
|
+
typeof runtime.version === 'string');
|
|
10
|
+
}
|
|
11
|
+
const IGNORED = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
12
|
+
const bun = Reflect.get(globalThis, 'Bun');
|
|
13
|
+
const [reportFd, list, file, ...args] = process.argv.slice(2);
|
|
14
|
+
if (!isBunSpawner(bun) || HOST_MEMORY === null || reportFd === undefined || list === undefined || file === undefined) {
|
|
15
|
+
throw new Error('peak-waiter runs on Bun, on Linux or macOS, as `peak-waiter.js <report fd> <fds> <file> [args…]`');
|
|
16
|
+
}
|
|
17
|
+
const report = (line) => {
|
|
18
|
+
try {
|
|
19
|
+
writeSync(Number(reportFd), `${JSON.stringify(line)}\n`);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// The executor that would read the report is gone.
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const passed = list === '' ? [] : list.split(',').map(Number);
|
|
26
|
+
const stdio = ['inherit', 'inherit', 'inherit'];
|
|
27
|
+
for (let fd = 3; fd <= Math.max(2, ...passed); fd += 1)
|
|
28
|
+
stdio.push(passed.includes(fd) ? fd : 'ignore');
|
|
29
|
+
const ignore = () => { };
|
|
30
|
+
for (const signal of IGNORED)
|
|
31
|
+
process.on(signal, ignore);
|
|
32
|
+
let child;
|
|
33
|
+
try {
|
|
34
|
+
child = bun.spawn([file, ...args], { stdio });
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
38
|
+
report({ unmeasured: `the command did not start: ${reason}` });
|
|
39
|
+
writeSync(2, `bounded-exec: could not start ${file}: ${reason}\n`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
report({ started: child.pid });
|
|
43
|
+
await child.exited;
|
|
44
|
+
const usage = child.resourceUsage();
|
|
45
|
+
report(usage === undefined
|
|
46
|
+
? { unmeasured: 'Bun read no resource usage for the exited command' }
|
|
47
|
+
: { peakBytes: HOST_MEMORY.peakBytes(usage.maxRSS, bun.version) });
|
|
48
|
+
if (child.signalCode !== null) {
|
|
49
|
+
for (const signal of IGNORED)
|
|
50
|
+
process.removeListener(signal, ignore);
|
|
51
|
+
process.kill(process.pid, child.signalCode);
|
|
52
|
+
}
|
|
53
|
+
process.exit(child.exitCode ?? 1);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admission decision of a CPU pool (`cpu-pool.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets
|
|
3
|
+
* itself"): which queued requests a pool grants, in FIFO order, from the tokens it has free and, for a run's own pool,
|
|
4
|
+
* the run's memory. Pure: the pool reads its jobserver fifo for the free count and keeps the holders' charges, and this
|
|
5
|
+
* decides.
|
|
6
|
+
*
|
|
7
|
+
* Every grant needs both. The head takes `min(want, free)` tokens once one is free, and only while the charges of the
|
|
8
|
+
* leaves holding grants plus its own fit the run's memory; a head that cannot be granted holds up every request behind
|
|
9
|
+
* it, and no request holds part of a grant while it waits for the rest. A leaf is charged its task's last recorded
|
|
10
|
+
* memory peak, and nothing while its task has none. A leaf whose own charge alone exceeds the run's memory could never
|
|
11
|
+
* fit, so it is granted once nothing else holds memory, and the grant says so.
|
|
12
|
+
*/
|
|
13
|
+
/** What a queued request asks: whole tokens, at least one, and its charge in bytes (0 for a task with no peak). */
|
|
14
|
+
export interface PoolAsk {
|
|
15
|
+
readonly want: number;
|
|
16
|
+
readonly memory: number;
|
|
17
|
+
}
|
|
18
|
+
/** The run's memory a pool charges against, and the bytes its holders are charged; null for a pool that charges none. */
|
|
19
|
+
export interface MemoryLedger {
|
|
20
|
+
readonly capacity: number;
|
|
21
|
+
readonly held: number;
|
|
22
|
+
}
|
|
23
|
+
/** One request's grant: the request, its tokens, and whether its charge alone exceeds the run's memory. */
|
|
24
|
+
export interface PoolGrant<Ask extends PoolAsk> {
|
|
25
|
+
readonly request: Ask;
|
|
26
|
+
readonly tokens: number;
|
|
27
|
+
readonly oversized: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The grants of the queue's first requests, in its order, and what the first request left waiting waits for: free
|
|
31
|
+
* tokens (`cpu`) or the run's memory (`memory`). `waiting` is null when every request was granted.
|
|
32
|
+
*/
|
|
33
|
+
export interface Admission<Ask extends PoolAsk> {
|
|
34
|
+
readonly grants: readonly PoolGrant<Ask>[];
|
|
35
|
+
readonly waiting: 'cpu' | 'memory' | null;
|
|
36
|
+
}
|
|
37
|
+
export declare function admit<Ask extends PoolAsk>(queue: readonly Ask[], available: number, memory: MemoryLedger | null): Admission<Ask>;
|
|
38
|
+
//# sourceMappingURL=pool-admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool-admission.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/pool-admission.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mHAAmH;AACnH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,yHAAyH;AACzH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,2GAA2G;AAC3G,MAAM,WAAW,SAAS,CAAC,GAAG,SAAS,OAAO;IAC5C,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,GAAG,SAAS,OAAO;IAC5C,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC;CAC3C;AAED,wBAAgB,KAAK,CAAC,GAAG,SAAS,OAAO,EACvC,KAAK,EAAE,SAAS,GAAG,EAAE,EACrB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,YAAY,GAAG,IAAI,GAC1B,SAAS,CAAC,GAAG,CAAC,CAkBhB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The admission decision of a CPU pool (`cpu-pool.ts`; specs/cowshed/05_gateway.md, "Without mbx, every Nx run budgets
|
|
3
|
+
* itself"): which queued requests a pool grants, in FIFO order, from the tokens it has free and, for a run's own pool,
|
|
4
|
+
* the run's memory. Pure: the pool reads its jobserver fifo for the free count and keeps the holders' charges, and this
|
|
5
|
+
* decides.
|
|
6
|
+
*
|
|
7
|
+
* Every grant needs both. The head takes `min(want, free)` tokens once one is free, and only while the charges of the
|
|
8
|
+
* leaves holding grants plus its own fit the run's memory; a head that cannot be granted holds up every request behind
|
|
9
|
+
* it, and no request holds part of a grant while it waits for the rest. A leaf is charged its task's last recorded
|
|
10
|
+
* memory peak, and nothing while its task has none. A leaf whose own charge alone exceeds the run's memory could never
|
|
11
|
+
* fit, so it is granted once nothing else holds memory, and the grant says so.
|
|
12
|
+
*/
|
|
13
|
+
export function admit(queue, available, memory) {
|
|
14
|
+
const grants = [];
|
|
15
|
+
let free = available;
|
|
16
|
+
let held = memory?.held ?? 0;
|
|
17
|
+
for (const request of queue) {
|
|
18
|
+
const oversized = memory !== null && request.memory > memory.capacity;
|
|
19
|
+
if (memory !== null && held + request.memory > memory.capacity && !(oversized && held === 0)) {
|
|
20
|
+
return { grants, waiting: 'memory' };
|
|
21
|
+
}
|
|
22
|
+
const tokens = Math.min(request.want, free);
|
|
23
|
+
if (tokens === 0) {
|
|
24
|
+
return { grants, waiting: 'cpu' };
|
|
25
|
+
}
|
|
26
|
+
free -= tokens;
|
|
27
|
+
held += request.memory;
|
|
28
|
+
grants.push({ request, tokens, oversized });
|
|
29
|
+
}
|
|
30
|
+
return { grants, waiting: null };
|
|
31
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src/project-graph/plugins/public-api.js';
|
|
2
|
+
import { type RunMemoryReading } from './host-memory.js';
|
|
2
3
|
/**
|
|
3
4
|
* The count of the pool a run is served, or null when it is served none. A run that inherits a pool (an enclosing
|
|
4
5
|
* executor's) takes from that one; with mbx, its pool is the host's one ledger, and a run pool beside it would count
|
|
@@ -6,11 +7,12 @@ import type { PostTasksExecutionContext, PreTasksExecutionContext } from 'nx/src
|
|
|
6
7
|
*/
|
|
7
8
|
export declare function runPoolTokens(env: Readonly<NodeJS.ProcessEnv>, cores: number): number | null;
|
|
8
9
|
/**
|
|
9
|
-
* Serve `context`'s run a pool of `runPoolTokens
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Serve `context`'s run a pool of `runPoolTokens`, charged against the run's memory `readMemory` reads, and publish it
|
|
11
|
+
* in `env`, which every task inherits, unless the run is served none. A run whose memory cannot be read throws
|
|
12
|
+
* `RunMemoryUnreadable`, which fails the run before any task starts: it is not shown to have room. A pool that cannot
|
|
13
|
+
* be made is said, and the run's tasks are then sized only by the ceilings they inherit.
|
|
12
14
|
*/
|
|
13
|
-
export declare function serveRunCpuPool(context: Pick<PreTasksExecutionContext, 'id'>, env?: NodeJS.ProcessEnv, cores?: number): Promise<void>;
|
|
15
|
+
export declare function serveRunCpuPool(context: Pick<PreTasksExecutionContext, 'id'>, env?: NodeJS.ProcessEnv, cores?: number, readMemory?: () => Promise<RunMemoryReading>): Promise<void>;
|
|
14
16
|
/** Close the pool `context`'s run was served, if it was served one. */
|
|
15
17
|
export declare function closeRunCpuPool(context: Pick<PostTasksExecutionContext, 'id'>): Promise<void>;
|
|
16
18
|
//# sourceMappingURL=run-cpu-pool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"run-cpu-pool.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/run-cpu-pool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAGtH,OAAO,EAAE,KAAK,gBAAgB,EAAsC,MAAM,kBAAkB,CAAC;AAqD7F;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5F;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,IAAI,CAAC,wBAAwB,EAAE,IAAI,CAAC,EAC7C,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,KAAK,GAAE,MAA+B,EACtC,UAAU,GAAE,MAAM,OAAO,CAAC,gBAAgB,CAAiB,GAC1D,OAAO,CAAC,IAAI,CAAC,CAoBf;AAoED,uEAAuE;AACvE,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAUnG"}
|
|
@@ -3,6 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { Worker } from 'node:worker_threads';
|
|
4
4
|
import { logger } from 'nx/src/devkit-exports.js';
|
|
5
5
|
import { readInheritedCpuPool } from './cpu-pool.js';
|
|
6
|
+
import { RunMemoryUnreadable, readRunMemory } from './host-memory.js';
|
|
6
7
|
import { mbxPool } from './mbx-pool.js';
|
|
7
8
|
import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
8
9
|
/**
|
|
@@ -20,6 +21,10 @@ import { CPU_TOKENS_ENV, parseInheritedTokens } from './runner-sizing.js';
|
|
|
20
21
|
* one token per core, or the inherited positive `BOUNDED_EXEC_CPU_TOKENS` when that is fewer: inside a cowshed job
|
|
21
22
|
* that count is the job's own, so the job's `--want` bounds the run.
|
|
22
23
|
*
|
|
24
|
+
* The pool also charges memory: each leaf is charged its task's last recorded peak, and granted only while the charges
|
|
25
|
+
* of the leaves holding grants and its own fit the run's memory (`host-memory.ts`: the cgroup's `memory.max` on Linux,
|
|
26
|
+
* else the host's). A run whose memory cannot be read does not start.
|
|
27
|
+
*
|
|
23
28
|
* The pool runs on a thread of its own (`cpu-pool-thread.ts`). The process that serves it, the Nx daemon when installed
|
|
24
29
|
* plugins load in it or the Nx CLI without one, hashes the run's tasks and builds its project graph in synchronous calls
|
|
25
30
|
* on its main thread. In a gate on 2026-10-28 one `hashPlans` ran for 14.2 s, and sixteen runners queued on a pool on
|
|
@@ -51,16 +56,21 @@ export function runPoolTokens(env, cores) {
|
|
|
51
56
|
return inherited === null ? cores : Math.min(inherited, cores);
|
|
52
57
|
}
|
|
53
58
|
/**
|
|
54
|
-
* Serve `context`'s run a pool of `runPoolTokens
|
|
55
|
-
*
|
|
56
|
-
*
|
|
59
|
+
* Serve `context`'s run a pool of `runPoolTokens`, charged against the run's memory `readMemory` reads, and publish it
|
|
60
|
+
* in `env`, which every task inherits, unless the run is served none. A run whose memory cannot be read throws
|
|
61
|
+
* `RunMemoryUnreadable`, which fails the run before any task starts: it is not shown to have room. A pool that cannot
|
|
62
|
+
* be made is said, and the run's tasks are then sized only by the ceilings they inherit.
|
|
57
63
|
*/
|
|
58
|
-
export async function serveRunCpuPool(context, env = process.env, cores = availableParallelism()) {
|
|
64
|
+
export async function serveRunCpuPool(context, env = process.env, cores = availableParallelism(), readMemory = readRunMemory) {
|
|
59
65
|
const tokens = runPoolTokens(env, cores);
|
|
60
66
|
if (tokens === null) {
|
|
61
67
|
return;
|
|
62
68
|
}
|
|
63
|
-
const
|
|
69
|
+
const memory = await readMemory();
|
|
70
|
+
if (!memory.ok) {
|
|
71
|
+
throw new RunMemoryUnreadable(memory.error);
|
|
72
|
+
}
|
|
73
|
+
const served = await servePoolThread(tokens, memory.memory.bytes);
|
|
64
74
|
if (!served.ok) {
|
|
65
75
|
logger.warn(`bounded-exec: this run's CPU pool failed (${served.error}); its tasks are sized only by the ceilings they inherit`);
|
|
66
76
|
return;
|
|
@@ -76,8 +86,11 @@ export async function serveRunCpuPool(context, env = process.env, cores = availa
|
|
|
76
86
|
* has said how its pool closed fails whichever wait is open, a later close returns that failure, and a thread lost while
|
|
77
87
|
* its pool serves is said at once.
|
|
78
88
|
*/
|
|
79
|
-
function servePoolThread(tokens) {
|
|
80
|
-
const thread = new Worker(THREAD_ENTRY, {
|
|
89
|
+
function servePoolThread(tokens, memory) {
|
|
90
|
+
const thread = new Worker(THREAD_ENTRY, {
|
|
91
|
+
workerData: { tokens, memory },
|
|
92
|
+
...THREAD_PRELOAD,
|
|
93
|
+
});
|
|
81
94
|
return new Promise((served) => {
|
|
82
95
|
let state = { kind: 'starting', served };
|
|
83
96
|
let closing;
|
|
@@ -104,6 +104,13 @@ export interface BoundedExecRecord {
|
|
|
104
104
|
* expired; written for the reader of a refused run, never read back.
|
|
105
105
|
*/
|
|
106
106
|
readonly cpuWait?: CpuWaitRow;
|
|
107
|
+
/**
|
|
108
|
+
* The command's memory peak in bytes when it ended (specs/cowshed/13_telemetry.md, "Job resource peaks"): its rusage
|
|
109
|
+
* `ru_maxrss`, the largest resident set any one process of its tree reached, as its waiter read it (`leaf-peak.ts`).
|
|
110
|
+
* Null when it was not measured: the command never ran, the waiter ended before it, or no Bun waited on it; never
|
|
111
|
+
* zero for that. The task's next run is charged it in its run's pool (`readLastPeak`).
|
|
112
|
+
*/
|
|
113
|
+
readonly peakBytes: number | null;
|
|
107
114
|
}
|
|
108
115
|
/** The Nx task a run executes as. Nx gives an executor no task id, only its parts. */
|
|
109
116
|
export interface BoundedExecTask {
|
|
@@ -223,6 +230,17 @@ export declare function clearTaskDirectory(directory: string): Promise<void>;
|
|
|
223
230
|
export declare function writeRecord(directory: string, record: BoundedExecRecord): Promise<void>;
|
|
224
231
|
/** The record in `directory`, or `null` when there is none. A malformed record throws. */
|
|
225
232
|
export declare function readRecord(directory: string): Promise<BoundedExecRecord | null>;
|
|
233
|
+
/**
|
|
234
|
+
* The peak the task's last record in `directory` names: its charge in its run's pool. Null when the task has no record
|
|
235
|
+
* or its record no peak; a record that cannot be read is an error naming it, never a charge of nothing.
|
|
236
|
+
*/
|
|
237
|
+
export declare function readLastPeak(directory: string): Promise<{
|
|
238
|
+
ok: true;
|
|
239
|
+
peakBytes: number | null;
|
|
240
|
+
} | {
|
|
241
|
+
ok: false;
|
|
242
|
+
error: string;
|
|
243
|
+
}>;
|
|
226
244
|
/** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
|
|
227
245
|
export declare function readJunitReport(directory: string, bunClosed?: (results: readonly NativeTestResult[]) => void): Promise<JunitFailures | null>;
|
|
228
246
|
/** A failed task of an Nx run, and whether its bounded-exec record shows only a bound. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verdict.d.ts","sourceRoot":"","sources":["../../../src/executors/bounded-exec/verdict.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAmB,KAAK,QAAQ,EAAe,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GAC9B,CAAC;IAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,kBAAkB,CAAC,GAChF;IACE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC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AsB,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAQvE;AACD,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CA2BnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAgBjE"}
|
|
@@ -321,6 +321,21 @@ export async function readRecord(directory) {
|
|
|
321
321
|
}
|
|
322
322
|
return parseRecord(JSON.parse(text));
|
|
323
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* The peak the task's last record in `directory` names: its charge in its run's pool. Null when the task has no record
|
|
326
|
+
* or its record no peak; a record that cannot be read is an error naming it, never a charge of nothing.
|
|
327
|
+
*/
|
|
328
|
+
export async function readLastPeak(directory) {
|
|
329
|
+
try {
|
|
330
|
+
return { ok: true, peakBytes: (await readRecord(directory))?.peakBytes ?? null };
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
return {
|
|
334
|
+
ok: false,
|
|
335
|
+
error: `the task's last record ${join(directory, VERDICT_FILE)} cannot be read: ${error instanceof Error ? error.message : String(error)}`,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
324
339
|
/** The JUnit report a command wrote into `directory`, or `null` when it wrote none. */
|
|
325
340
|
export async function readJunitReport(directory, bunClosed) {
|
|
326
341
|
try {
|
|
@@ -341,7 +356,12 @@ function parseRecord(value) {
|
|
|
341
356
|
if (!isObject(value) || typeof value.task !== 'string' || !(typeof value.hash === 'string' || value.hash === null)) {
|
|
342
357
|
throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
|
|
343
358
|
}
|
|
344
|
-
|
|
359
|
+
// A record written before peaks were recorded carries none.
|
|
360
|
+
const peakBytes = value.peakBytes ?? null;
|
|
361
|
+
if (!(peakBytes === null || (typeof peakBytes === 'number' && Number.isSafeInteger(peakBytes) && peakBytes >= 0))) {
|
|
362
|
+
throw new Error(`not a bounded-exec record: ${JSON.stringify(value)}`);
|
|
363
|
+
}
|
|
364
|
+
return { task: value.task, hash: value.hash, verdict: parseVerdict(value.verdict), peakBytes };
|
|
345
365
|
}
|
|
346
366
|
function parseVerdict(value) {
|
|
347
367
|
if (isObject(value)) {
|
package/package.json
CHANGED
|
@@ -9,13 +9,14 @@ import { type CloseOutcome, createCpuPool } from './cpu-pool.js';
|
|
|
9
9
|
* jobserver fifo and heartbeat share an event loop that runs nothing else, so the heartbeat proves that the actor which
|
|
10
10
|
* admits and grants is turning.
|
|
11
11
|
*
|
|
12
|
-
* The thread is started with the pool's count. It says once that the pool serves, with the environment a task inherits,
|
|
12
|
+
* The thread is started with the pool's count and the run's memory. It says once that the pool serves, with the environment a task inherits,
|
|
13
13
|
* or why it cannot; the host's one message is its close, after which the thread says how the pool closed.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
/** What the thread is started with. */
|
|
16
|
+
/** What the thread is started with: the run's count, and the run's memory in bytes its grants are charged against. */
|
|
17
17
|
export interface CpuPoolThreadData {
|
|
18
18
|
readonly tokens: number;
|
|
19
|
+
readonly memory: number;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/** What the thread says, in order: the pool serves or failed; after the host's close, how the pool closed. */
|
|
@@ -31,7 +32,7 @@ if (host === null) {
|
|
|
31
32
|
const report = (message: CpuPoolThreadReport): void => host.postMessage(message);
|
|
32
33
|
const data: CpuPoolThreadData = workerData;
|
|
33
34
|
// The pool lives until its host closes it, or with the thread.
|
|
34
|
-
const made = await createCpuPool(data.tokens, new Promise<void>(() => {}));
|
|
35
|
+
const made = await createCpuPool(data.tokens, new Promise<void>(() => {}), data.memory);
|
|
35
36
|
if (made.ok) {
|
|
36
37
|
const { pool } = made;
|
|
37
38
|
host.once('message', () => {
|