refactor(process): give the prlimit producer budget one owner (#2698)
Squash merge of https://github.com/morluto/rea/pull/2698. Co-authored-by: NIU-123370 <191000457+NIU-123370@users.noreply.github.com>
This commit is contained in:
co-authored by
NIU-123370
parent
f825c869d6
commit
782cc3b060
@@ -8,6 +8,8 @@ import {
|
||||
FIELD_RECORD_BUDGET,
|
||||
} from "./parseFieldDiscovery.js";
|
||||
import {
|
||||
BOUNDED_PRODUCER_LIMITS as LIMITS,
|
||||
prlimitArgumentVector,
|
||||
readLinuxResourceLimits,
|
||||
type LinuxResourceLimits,
|
||||
} from "../process/LinuxResourceLimits.js";
|
||||
@@ -60,15 +62,6 @@ export const TSHARK_PROVIDER_IDENTITY = {
|
||||
name: "REA TShark capture adapter",
|
||||
version: "tshark@4",
|
||||
} as const;
|
||||
// Bound the resident input copy and retained text before allocation/collection.
|
||||
const LIMITS = {
|
||||
input_bytes: 32 * 1024 * 1024,
|
||||
output_bytes: 4 * 1024 * 1024,
|
||||
command_timeout_ms: 30_000,
|
||||
address_space_bytes: 1024 * 1024 * 1024,
|
||||
file_bytes: 64 * 1024 * 1024,
|
||||
cpu_seconds: 30,
|
||||
} as const;
|
||||
type Launcher = NonNullable<Parameters<typeof runOwnedCommand>[2]>["launcher"];
|
||||
|
||||
/** Inspect selected capture files only, retaining cleanup ownership across failures. */
|
||||
@@ -165,14 +158,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
||||
options?.signal,
|
||||
);
|
||||
effectiveLimits = await this.#resources.readLimits(limits);
|
||||
const limitArguments = [
|
||||
`--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
|
||||
`--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
|
||||
`--cpu=${effectiveLimits.cpu_seconds}:${effectiveLimits.cpu_seconds}`,
|
||||
"--core=0:0",
|
||||
"--",
|
||||
command,
|
||||
];
|
||||
const limitArguments = prlimitArgumentVector(effectiveLimits, command);
|
||||
phase = "workspace";
|
||||
root = await this.createRuntime();
|
||||
this.#resources.retain(root, undefined);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { clampLinuxResourceLimits } from "./LinuxResourceLimits.js";
|
||||
import {
|
||||
BOUNDED_PRODUCER_LIMITS,
|
||||
clampLinuxResourceLimits,
|
||||
prlimitArgumentVector,
|
||||
} from "./LinuxResourceLimits.js";
|
||||
const configured = {
|
||||
address_space_bytes: 1073741824,
|
||||
file_bytes: 67108864,
|
||||
@@ -41,3 +45,38 @@ it("refuses missing, ambiguous or malformed kernel limits before launch", () =>
|
||||
])
|
||||
expect(() => clampLinuxResourceLimits(configured, value)).toThrow();
|
||||
});
|
||||
it("pins the shared producer budget in one place", () => {
|
||||
expect(BOUNDED_PRODUCER_LIMITS).toEqual({
|
||||
input_bytes: 33554432,
|
||||
output_bytes: 4194304,
|
||||
command_timeout_ms: 30000,
|
||||
address_space_bytes: 1073741824,
|
||||
file_bytes: 67108864,
|
||||
cpu_seconds: 30,
|
||||
});
|
||||
});
|
||||
it("pairs each effective ceiling with itself before the producer argv", () => {
|
||||
expect(
|
||||
prlimitArgumentVector(BOUNDED_PRODUCER_LIMITS, "/bin/producer"),
|
||||
).toEqual([
|
||||
"--as=1073741824:1073741824",
|
||||
"--fsize=67108864:67108864",
|
||||
"--cpu=30:30",
|
||||
"--core=0:0",
|
||||
"--",
|
||||
"/bin/producer",
|
||||
]);
|
||||
expect(
|
||||
prlimitArgumentVector(
|
||||
clampLinuxResourceLimits(BOUNDED_PRODUCER_LIMITS, report("10 20")),
|
||||
"/bin/producer",
|
||||
),
|
||||
).toEqual([
|
||||
"--as=10:10",
|
||||
"--fsize=67108864:67108864",
|
||||
"--cpu=30:30",
|
||||
"--core=0:0",
|
||||
"--",
|
||||
"/bin/producer",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -15,6 +15,29 @@ const rows = {
|
||||
cpu_seconds: "Max cpu time",
|
||||
} as const;
|
||||
|
||||
/** Bound the resident input copy and retained text before allocation/collection. */
|
||||
export const BOUNDED_PRODUCER_LIMITS = {
|
||||
input_bytes: 32 * 1024 * 1024,
|
||||
output_bytes: 4 * 1024 * 1024,
|
||||
command_timeout_ms: 30_000,
|
||||
address_space_bytes: 1024 * 1024 * 1024,
|
||||
file_bytes: 64 * 1024 * 1024,
|
||||
cpu_seconds: 30,
|
||||
} as const;
|
||||
|
||||
/** Pin soft and hard ceilings together, then hand the producer argv to the limiter. */
|
||||
export const prlimitArgumentVector = (
|
||||
limits: LinuxResourceLimits,
|
||||
command: string,
|
||||
): string[] => [
|
||||
`--as=${limits.address_space_bytes}:${limits.address_space_bytes}`,
|
||||
`--fsize=${limits.file_bytes}:${limits.file_bytes}`,
|
||||
`--cpu=${limits.cpu_seconds}:${limits.cpu_seconds}`,
|
||||
"--core=0:0",
|
||||
"--",
|
||||
command,
|
||||
];
|
||||
|
||||
/** Never raise either inherited soft policy or hard ceiling. */
|
||||
export const clampLinuxResourceLimits = (
|
||||
configured: LinuxResourceLimits,
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
parseDecoderDiscovery,
|
||||
} from "./parseDecoderDiscovery.js";
|
||||
import {
|
||||
BOUNDED_PRODUCER_LIMITS as LIMITS,
|
||||
prlimitArgumentVector,
|
||||
readLinuxResourceLimits,
|
||||
type LinuxResourceLimits,
|
||||
} from "../process/LinuxResourceLimits.js";
|
||||
@@ -59,15 +61,6 @@ export const SIGROK_PROVIDER_IDENTITY = {
|
||||
name: "REA sigrok recording adapter",
|
||||
version: "sigrok-cli@0.7.2",
|
||||
} as const;
|
||||
// Bound the resident input copy and retained text before allocation/collection.
|
||||
const LIMITS = {
|
||||
input_bytes: 32 * 1024 * 1024,
|
||||
output_bytes: 4 * 1024 * 1024,
|
||||
command_timeout_ms: 30_000,
|
||||
address_space_bytes: 1024 * 1024 * 1024,
|
||||
file_bytes: 64 * 1024 * 1024,
|
||||
cpu_seconds: 30,
|
||||
} as const;
|
||||
type Launcher = NonNullable<Parameters<typeof runOwnedCommand>[2]>["launcher"];
|
||||
|
||||
/** Decode selected recordings only, retaining cleanup ownership across failures. */
|
||||
@@ -163,14 +156,7 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
|
||||
options?.signal,
|
||||
);
|
||||
effectiveLimits = await this.#resources.readLimits(LIMITS);
|
||||
const limitArguments = [
|
||||
`--as=${effectiveLimits.address_space_bytes}:${effectiveLimits.address_space_bytes}`,
|
||||
`--fsize=${effectiveLimits.file_bytes}:${effectiveLimits.file_bytes}`,
|
||||
`--cpu=${effectiveLimits.cpu_seconds}:${effectiveLimits.cpu_seconds}`,
|
||||
"--core=0:0",
|
||||
"--",
|
||||
command,
|
||||
];
|
||||
const limitArguments = prlimitArgumentVector(effectiveLimits, command);
|
||||
phase = "workspace";
|
||||
root = await this.createRuntime();
|
||||
this.#resources.retain(root, undefined);
|
||||
|
||||
Reference in New Issue
Block a user