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:
The one -Niu
2026-10-13 23:47:41 +08:00
committed by GitHub
co-authored by NIU-123370
parent f825c869d6
commit 782cc3b060
5 changed files with 93 additions and 35 deletions
+40 -1
View File
@@ -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",
]);
});
+23
View File
@@ -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,