@isentinel/machine-budget 0.1.0 → 0.2.0
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 +18 -3
- package/bin/machine-budget-status.js +15 -0
- package/dist/admission-DcnnK4uq.d.mts +35 -0
- package/dist/index.d.mts +1 -21
- package/dist/index.mjs +233 -673
- package/dist/run-text-1kRifnCt.mjs +663 -0
- package/dist/status-cli.d.mts +53 -0
- package/dist/status-cli.mjs +51 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -37,9 +37,12 @@ budget.close();
|
|
|
37
37
|
`leaseAsync` waits until the minimum fits, then grants the most workers that
|
|
38
38
|
fit. A request with a `cost` uses the learned memory of one worker once three
|
|
39
39
|
peaks are known, and `memoryPerWorker` before that. Costs are kept per git
|
|
40
|
-
clone: all worktrees of one clone share them. A waiting request prints
|
|
41
|
-
through `log
|
|
42
|
-
|
|
40
|
+
clone: all worktrees of one clone share them. A waiting request prints a line
|
|
41
|
+
through `log` that names the reason and each other run that holds leases: its
|
|
42
|
+
pid, its `workspaceRoot`, and its leased memory and threads. Behind an older
|
|
43
|
+
request, the line names the run of that request and its size instead. It prints
|
|
44
|
+
again when the reason or the named runs change. `isShared` is true when leases
|
|
45
|
+
come from the shared ledger, and false when the budget is off.
|
|
43
46
|
|
|
44
47
|
A run that resizes while it runs holds one lease for each worker. `tryLease`
|
|
45
48
|
grants the most workers that fit now, or returns `undefined`, and never waits.
|
|
@@ -86,6 +89,18 @@ so a process that starts and exits between two samples is missed.
|
|
|
86
89
|
- `MACHINE_BUDGET_DIR` moves the ledger. The default is `machine-budget-<user>`
|
|
87
90
|
in the system temp directory.
|
|
88
91
|
|
|
92
|
+
## See the ledger
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
npx machine-budget-status
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`machine-budget-status` prints each run with its pid, its `workspaceRoot` and
|
|
99
|
+
the age of its heartbeat; each lease with its run, lane, memory and threads; and
|
|
100
|
+
each waiting request with its run, size and wait time. It opens the ledger
|
|
101
|
+
read-only: it does not take back dead runs or make the ledger, and it honours
|
|
102
|
+
`MACHINE_BUDGET_DIR`. In this repo, `pnpm machine-budget:status` runs it.
|
|
103
|
+
|
|
89
104
|
## License
|
|
90
105
|
|
|
91
106
|
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const sourceEntry = resolve(dirname(fileURLToPath(import.meta.url)), "../src/status-cli.ts");
|
|
7
|
+
|
|
8
|
+
let main;
|
|
9
|
+
if (existsSync(sourceEntry)) {
|
|
10
|
+
({ main } = await import("../src/status-cli.ts"));
|
|
11
|
+
} else {
|
|
12
|
+
({ main } = await import("../dist/status-cli.mjs"));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
main();
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** A lease that a session holds. */
|
|
2
|
+
interface HeldLease {
|
|
3
|
+
/** The pool of the lease. */
|
|
4
|
+
lane: Lane;
|
|
5
|
+
/** The leased memory, in bytes. */
|
|
6
|
+
memory: number;
|
|
7
|
+
/** The session that holds the lease. */
|
|
8
|
+
session: string;
|
|
9
|
+
/** The leased threads. */
|
|
10
|
+
threads: number;
|
|
11
|
+
}
|
|
12
|
+
/** A request that waits for a lease. */
|
|
13
|
+
interface Waiter {
|
|
14
|
+
/** The id of the request. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Whether the request is too big for the small-job lane. */
|
|
17
|
+
isBig: boolean;
|
|
18
|
+
/** The session that made the request. */
|
|
19
|
+
session: string;
|
|
20
|
+
/** When the request started to wait, in epoch milliseconds. */
|
|
21
|
+
since: number;
|
|
22
|
+
}
|
|
23
|
+
/** The worker range and the memory of one worker. */
|
|
24
|
+
interface WorkerRequest {
|
|
25
|
+
/** Keeps the request out of the small-job lane, for leases held long. */
|
|
26
|
+
isMainLaneOnly?: boolean;
|
|
27
|
+
/** The most workers the client can use. */
|
|
28
|
+
maxWorkers: number;
|
|
29
|
+
/** The memory of one worker, in bytes. */
|
|
30
|
+
memoryPerWorker: number;
|
|
31
|
+
/** The fewest workers the client can run with. */
|
|
32
|
+
minWorkers: number;
|
|
33
|
+
}
|
|
34
|
+
type Lane = "main" | "small";
|
|
35
|
+
export { Waiter as n, WorkerRequest as r, HeldLease as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/** The worker range and the memory of one worker. */
|
|
3
|
-
interface WorkerRequest {
|
|
4
|
-
/** Keeps the request out of the small-job lane, for leases held long. */
|
|
5
|
-
isMainLaneOnly?: boolean;
|
|
6
|
-
/** The most workers the client can use. */
|
|
7
|
-
maxWorkers: number;
|
|
8
|
-
/** The memory of one worker, in bytes. */
|
|
9
|
-
memoryPerWorker: number;
|
|
10
|
-
/** The fewest workers the client can run with. */
|
|
11
|
-
minWorkers: number;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/learned-cost.d.ts
|
|
1
|
+
import { r as WorkerRequest } from "./admission-DcnnK4uq.mjs";
|
|
15
2
|
/** What a cost is learned for, inside one clone. */
|
|
16
3
|
interface CostScope {
|
|
17
4
|
/** The pass of the tool, such as `type-aware`. */
|
|
@@ -19,8 +6,6 @@ interface CostScope {
|
|
|
19
6
|
/** The project the worker runs for. */
|
|
20
7
|
project: string;
|
|
21
8
|
}
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/budget-types.d.ts
|
|
24
9
|
/** What one child process asks for. */
|
|
25
10
|
interface LeaseRequest extends WorkerRequest {
|
|
26
11
|
/** What to learn the cost for; without it, `memoryPerWorker` is used. */
|
|
@@ -58,8 +43,6 @@ interface MachineBudget {
|
|
|
58
43
|
/** Leases the most workers that fit now, or nothing, and never waits. */
|
|
59
44
|
tryLease: (request: LeaseRequest) => Lease | undefined;
|
|
60
45
|
}
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/tree-watch.d.ts
|
|
63
46
|
/**
|
|
64
47
|
* The peaks of a process tree in bytes, undefined where the platform cannot
|
|
65
48
|
* read them.
|
|
@@ -78,8 +61,6 @@ interface TreeWatch {
|
|
|
78
61
|
/** Stops the watch and returns the peaks since it began. */
|
|
79
62
|
stop: () => TreePeaks;
|
|
80
63
|
}
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/index.d.ts
|
|
83
64
|
/** How a run joins the machine budget. */
|
|
84
65
|
export interface MachineBudgetOptions {
|
|
85
66
|
/** Prints the one line of a waiting request, such as `console.error`. */
|
|
@@ -108,5 +89,4 @@ export declare function openMachineBudget(options: MachineBudgetOptions): Machin
|
|
|
108
89
|
* @returns The watch; stop it once the process exits.
|
|
109
90
|
*/
|
|
110
91
|
export declare function watchTree(pid: number): TreeWatch;
|
|
111
|
-
//#endregion
|
|
112
92
|
export type { CostScope, Lease, LeaseReport, LeaseRequest, MachineBudget, TreePeaks, TreeWatch };
|