@norskvideo/ctl-test-harness 0.1.90 → 0.1.91
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/demo/harness.js +6 -1
- package/demo/run.d.ts +3 -0
- package/demo/run.js +2 -1
- package/launch.d.ts +16 -0
- package/launch.js +63 -0
- package/package.json +1 -1
- package/smoke.d.ts +3 -0
- package/smoke.js +7 -1
package/demo/harness.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// program SRT listener, an HLS ladder), its config-schema port remap for a
|
|
15
15
|
// built template, and whatever sidecar its output points at.
|
|
16
16
|
import { netReachMode, STUDIO_INTERNAL_PORT, studioBaseFrom } from "../container-net.js";
|
|
17
|
-
import { ctlSupportsPublishDebugPorts } from "../launch.js";
|
|
17
|
+
import { cpuPinningArgv, ctlSupportsPublishDebugPorts, launchCpuPinning } from "../launch.js";
|
|
18
18
|
import { pollUntil } from "../poll.js";
|
|
19
19
|
import { launchWithPortConflictRetry, reapInstance } from "../reap.js";
|
|
20
20
|
import { DemoGateFailure } from "./gates.js";
|
|
@@ -173,6 +173,11 @@ export class ProductHarness {
|
|
|
173
173
|
const user = deps.containerUser();
|
|
174
174
|
if (user)
|
|
175
175
|
launchArgv.push("--container-user", user);
|
|
176
|
+
const cores = await (deps.cpuPinning ?? launchCpuPinning)();
|
|
177
|
+
if (cores) {
|
|
178
|
+
launchArgv.push(...cpuPinningArgv(cores));
|
|
179
|
+
deps.log(`pinned to this runner's cpuset: ${cores.join(",")}`);
|
|
180
|
+
}
|
|
176
181
|
if (internalOnly)
|
|
177
182
|
launchArgv.push("--internal-only");
|
|
178
183
|
// ctl binds a product's studio host port to 127.0.0.1. Every gate that
|
package/demo/run.d.ts
CHANGED
|
@@ -93,6 +93,9 @@ export interface DemoDeps {
|
|
|
93
93
|
* existing custom-deps consumer keeps working; absent = probe the CLI. */
|
|
94
94
|
supportsPublishDebugPorts?(): Promise<boolean>;
|
|
95
95
|
containerUser(): string | undefined;
|
|
96
|
+
/** The cores to pin a launch to (the runner's cpuset on a CI box); absent =
|
|
97
|
+
* launch.ts launchCpuPinning, undefined = unpinned. */
|
|
98
|
+
cpuPinning?(): Promise<number[] | undefined>;
|
|
96
99
|
/** Symlinks under an exported workdir whose target does not exist, as
|
|
97
100
|
* `<link> -> <target>` lines. */
|
|
98
101
|
brokenSymlinks(dir: string): string[];
|
package/demo/run.js
CHANGED
|
@@ -33,7 +33,7 @@ import { preserveInstanceContainerLogs } from "../container-logs.js";
|
|
|
33
33
|
import { currentInstanceNetworks, DOCKER_NETWORK_NAME, ensureRunnerOnNetwork, instanceNetworkName, isAlreadyOnNetworkError, netReachMode, } from "../container-net.js";
|
|
34
34
|
import { cleanupDaemon, ctlSupportsEphemeralPorts, PROXY_PORT_FILE, requireLicenseFile, runCli, startDaemon, } from "../daemon.js";
|
|
35
35
|
import { hashSlot } from "../harness-config.js";
|
|
36
|
-
import { ctlSupportsNoPublish, ctlSupportsPublishDebugPorts, runnerContainerUser } from "../launch.js";
|
|
36
|
+
import { ctlSupportsNoPublish, ctlSupportsPublishDebugPorts, launchCpuPinning, runnerContainerUser, } from "../launch.js";
|
|
37
37
|
import { pollUntil } from "../poll.js";
|
|
38
38
|
import { nukePathAsRoot, reportForeignOwners } from "../root-nuke.js";
|
|
39
39
|
import { startSrtSources } from "../source-pump.js";
|
|
@@ -304,6 +304,7 @@ export function defaultDemoDeps(cwd) {
|
|
|
304
304
|
supportsNoPublish: ctlSupportsNoPublish,
|
|
305
305
|
supportsPublishDebugPorts: ctlSupportsPublishDebugPorts,
|
|
306
306
|
containerUser: runnerContainerUser,
|
|
307
|
+
cpuPinning: launchCpuPinning,
|
|
307
308
|
brokenSymlinks: findBrokenSymlinks,
|
|
308
309
|
state: fileStateStore(cwd),
|
|
309
310
|
hold: (abort) => new Promise((res) => {
|
package/launch.d.ts
CHANGED
|
@@ -31,3 +31,19 @@ export declare function withNoPublish<T>(opts: T & {
|
|
|
31
31
|
}): Promise<T & {
|
|
32
32
|
internalOnly?: boolean;
|
|
33
33
|
}>;
|
|
34
|
+
/** The kernel's cpu list format (`0-3,8,10-11`) as core numbers. */
|
|
35
|
+
export declare function parseCpuList(list: string): number[];
|
|
36
|
+
/** The cores this process is restricted to, when that is fewer than the host
|
|
37
|
+
* has online; undefined for an unrestricted process or an unreadable list. */
|
|
38
|
+
export declare function restrictedCpus(lists: {
|
|
39
|
+
effective: string | undefined;
|
|
40
|
+
online: string | undefined;
|
|
41
|
+
}): number[] | undefined;
|
|
42
|
+
/** This process's own cpuset (cgroup v2, else v1) against the host's online cpus. */
|
|
43
|
+
export declare function runnerCpus(): number[] | undefined;
|
|
44
|
+
/** The cores to pin a launch to: the runner's cpuset in `direct` reach mode (a
|
|
45
|
+
* runner container on a shared docker daemon), when the resolved ctl takes
|
|
46
|
+
* `--cpu-pinning`. Undefined anywhere else, which launches unpinned. */
|
|
47
|
+
export declare function launchCpuPinning(): Promise<number[] | undefined>;
|
|
48
|
+
/** `--cpu-pinning` argv for `cores`, one flag per core as the CLI takes them. */
|
|
49
|
+
export declare function cpuPinningArgv(cores: readonly number[] | undefined): string[];
|
package/launch.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// This is the prevention half; @norskvideo/ctl-test-harness/daemon's
|
|
10
10
|
// cleanupDaemon is the tolerance half (root-nuke on teardown). Pairing the two
|
|
11
11
|
// is the harness's whole "launch clean, tear down clean" story.
|
|
12
|
+
import { readFileSync } from "node:fs";
|
|
12
13
|
import { cliCommand } from "./cli-command.js";
|
|
13
14
|
import { netReachMode } from "./container-net.js";
|
|
14
15
|
/** The `uid:gid` the current process runs as, for docker `--container-user`, or
|
|
@@ -43,6 +44,7 @@ export function withContainerUser(opts) {
|
|
|
43
44
|
// spawn per process.
|
|
44
45
|
const INTERNAL_ONLY_FLAG = "--internal-only";
|
|
45
46
|
const PUBLISH_DEBUG_PORTS_FLAG = "--publish-debug-ports";
|
|
47
|
+
const CPU_PINNING_FLAG = "--cpu-pinning";
|
|
46
48
|
const flagSupport = new Map();
|
|
47
49
|
async function probeFlagSupport(flag) {
|
|
48
50
|
try {
|
|
@@ -91,3 +93,64 @@ export async function withNoPublish(opts) {
|
|
|
91
93
|
return opts;
|
|
92
94
|
return (await ctlSupportsNoPublish()) ? { ...opts, internalOnly: true } : opts;
|
|
93
95
|
}
|
|
96
|
+
// A CI runner is a container pinned to a cpuset, but on docker-outside-of-docker
|
|
97
|
+
// the instances it launches run on the host daemon with no pin: two jobs on one
|
|
98
|
+
// box then contend for every core, while each job's measuring browser stays on
|
|
99
|
+
// its own few (commentary's ears went from 0 to 38 breaks a minute beside
|
|
100
|
+
// another job). Pinning a launch to the runner's own cpuset keeps each job on
|
|
101
|
+
// the cores it was given.
|
|
102
|
+
/** The kernel's cpu list format (`0-3,8,10-11`) as core numbers. */
|
|
103
|
+
export function parseCpuList(list) {
|
|
104
|
+
const cores = [];
|
|
105
|
+
for (const part of list.trim().split(",")) {
|
|
106
|
+
const m = /^(\d+)(?:-(\d+))?$/.exec(part.trim());
|
|
107
|
+
if (!m)
|
|
108
|
+
continue;
|
|
109
|
+
const lo = Number(m[1]);
|
|
110
|
+
const hi = m[2] === undefined ? lo : Number(m[2]);
|
|
111
|
+
for (let c = lo; c <= hi; c++)
|
|
112
|
+
cores.push(c);
|
|
113
|
+
}
|
|
114
|
+
return cores;
|
|
115
|
+
}
|
|
116
|
+
/** The cores this process is restricted to, when that is fewer than the host
|
|
117
|
+
* has online; undefined for an unrestricted process or an unreadable list. */
|
|
118
|
+
export function restrictedCpus(lists) {
|
|
119
|
+
if (lists.effective === undefined || lists.online === undefined)
|
|
120
|
+
return undefined;
|
|
121
|
+
const effective = parseCpuList(lists.effective);
|
|
122
|
+
const online = parseCpuList(lists.online);
|
|
123
|
+
if (effective.length === 0 || effective.length >= online.length)
|
|
124
|
+
return undefined;
|
|
125
|
+
return effective;
|
|
126
|
+
}
|
|
127
|
+
function readOr(path) {
|
|
128
|
+
try {
|
|
129
|
+
return readFileSync(path, "utf8");
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** This process's own cpuset (cgroup v2, else v1) against the host's online cpus. */
|
|
136
|
+
export function runnerCpus() {
|
|
137
|
+
return restrictedCpus({
|
|
138
|
+
effective: readOr("/sys/fs/cgroup/cpuset.cpus.effective") ?? readOr("/sys/fs/cgroup/cpuset/cpuset.effective_cpus"),
|
|
139
|
+
online: readOr("/sys/devices/system/cpu/online"),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/** The cores to pin a launch to: the runner's cpuset in `direct` reach mode (a
|
|
143
|
+
* runner container on a shared docker daemon), when the resolved ctl takes
|
|
144
|
+
* `--cpu-pinning`. Undefined anywhere else, which launches unpinned. */
|
|
145
|
+
export async function launchCpuPinning() {
|
|
146
|
+
if (netReachMode() !== "direct")
|
|
147
|
+
return undefined;
|
|
148
|
+
const cores = runnerCpus();
|
|
149
|
+
if (!cores)
|
|
150
|
+
return undefined;
|
|
151
|
+
return (await ctlSupportsFlag(CPU_PINNING_FLAG)) ? cores : undefined;
|
|
152
|
+
}
|
|
153
|
+
/** `--cpu-pinning` argv for `cores`, one flag per core as the CLI takes them. */
|
|
154
|
+
export function cpuPinningArgv(cores) {
|
|
155
|
+
return (cores ?? []).flatMap((c) => [CPU_PINNING_FLAG, String(c)]);
|
|
156
|
+
}
|
package/package.json
CHANGED
package/smoke.d.ts
CHANGED
|
@@ -193,6 +193,9 @@ export interface SmokeDeps {
|
|
|
193
193
|
* existing custom-deps consumer keeps working; absent = probe the CLI. */
|
|
194
194
|
supportsPublishDebugPorts?(): Promise<boolean>;
|
|
195
195
|
containerUser(): string | undefined;
|
|
196
|
+
/** The cores to pin a launch to (the runner's cpuset on a CI box); absent =
|
|
197
|
+
* launch.ts launchCpuPinning, undefined = unpinned. */
|
|
198
|
+
cpuPinning?(): Promise<number[] | undefined>;
|
|
196
199
|
/** Diagnostic dump for a satisfied-phase timeout, taken while the instance
|
|
197
200
|
* is still up. Optional so an existing custom-deps consumer keeps working;
|
|
198
201
|
* the default reads every container carrying the instance's label. */
|
package/smoke.js
CHANGED
|
@@ -24,7 +24,7 @@ import { authority, ensureRunnerOnNetwork, netReachMode, resolveEndpoint, STUDIO
|
|
|
24
24
|
import { cleanupDaemon, ctlSupportsEphemeralPorts, PROXY_PORT_FILE, requireLicenseFile, runCli, startDaemon, } from "./daemon.js";
|
|
25
25
|
import { freeHostPort } from "./free-port.js";
|
|
26
26
|
import { hashSlot } from "./harness-config.js";
|
|
27
|
-
import { ctlSupportsNoPublish, ctlSupportsPublishDebugPorts, runnerContainerUser } from "./launch.js";
|
|
27
|
+
import { cpuPinningArgv, ctlSupportsNoPublish, ctlSupportsPublishDebugPorts, launchCpuPinning, runnerContainerUser, } from "./launch.js";
|
|
28
28
|
import { pollUntil } from "./poll.js";
|
|
29
29
|
import { launchWithPortConflictRetry, reapInstance } from "./reap.js";
|
|
30
30
|
import { nukePathAsRoot, reportForeignOwners } from "./root-nuke.js";
|
|
@@ -85,6 +85,7 @@ export const defaultSmokeDeps = {
|
|
|
85
85
|
supportsNoPublish: ctlSupportsNoPublish,
|
|
86
86
|
supportsPublishDebugPorts: ctlSupportsPublishDebugPorts,
|
|
87
87
|
containerUser: runnerContainerUser,
|
|
88
|
+
cpuPinning: launchCpuPinning,
|
|
88
89
|
diagnose: (instanceId) => dumpInstanceContainerLogs(instanceId),
|
|
89
90
|
fetchProductRoute: async ({ daemonPort, product, route, storeDir }) => {
|
|
90
91
|
// The daemon fronts the product proxy with the same auth guard as /api/*,
|
|
@@ -418,6 +419,11 @@ export async function runProductSmoke(slug, spec, deps = defaultSmokeDeps) {
|
|
|
418
419
|
const user = deps.containerUser();
|
|
419
420
|
if (user)
|
|
420
421
|
flags.push("--container-user", user);
|
|
422
|
+
const cores = await (deps.cpuPinning ?? launchCpuPinning)();
|
|
423
|
+
if (cores) {
|
|
424
|
+
flags.push(...cpuPinningArgv(cores));
|
|
425
|
+
deps.log(`pinned to this runner's cpuset: ${cores.join(",")}`);
|
|
426
|
+
}
|
|
421
427
|
if (internalOnly)
|
|
422
428
|
flags.push("--internal-only");
|
|
423
429
|
// ctl binds a product's OPERATOR compose ports (STUDIO_HOST_PORT among
|