Skip to content

Commit 05a03c6

Browse files
fix: cap local tsgo CPU usage (#119517)
1 parent 3faa2b0 commit 05a03c6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎scripts/lib/local-heavy-check-runtime.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from "node:path";
66

77
const GIB = 1024 ** 3;
88
const DEFAULT_LOCAL_GO_GC = "30";
9+
const DEFAULT_LOCAL_GO_MAX_PROCS = "1";
910
const DEFAULT_LOCAL_GO_MEMORY_LIMIT = "3GiB";
1011
const DEFAULT_LOCAL_TSGO_BUILD_INFO_FILE = ".artifacts/tsgo-cache/root.tsbuildinfo";
1112
const DEFAULT_LOCK_TIMEOUT_MS = 10 * 60 * 1000;
@@ -141,6 +142,9 @@ export function applyLocalTsgoPolicy(args, env, hostResources) {
141142
insertBeforeSeparator(nextArgs, "--singleThreaded");
142143
insertBeforeSeparator(nextArgs, "--checkers", "1");
143144

145+
if (!nextEnv.GOMAXPROCS) {
146+
nextEnv.GOMAXPROCS = DEFAULT_LOCAL_GO_MAX_PROCS;
147+
}
144148
if (!nextEnv.GOGC) {
145149
nextEnv.GOGC = DEFAULT_LOCAL_GO_GC;
146150
}

‎test/scripts/local-heavy-check-runtime.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ describe("local-heavy-check-runtime", () => {
148148
"--checkers",
149149
"1",
150150
]);
151+
expect(env.GOMAXPROCS).toBe("1");
151152
expect(env.GOGC).toBe("30");
152153
expect(env.GOMEMLIMIT).toBe("3GiB");
153154
});
@@ -162,6 +163,7 @@ describe("local-heavy-check-runtime", () => {
162163
const { args, env } = applyLocalTsgoPolicy(
163164
["--checkers", "4", "--singleThreaded", "--pprofDir", "/tmp/existing"],
164165
makeEnv({
166+
GOMAXPROCS: "3",
165167
GOGC: "80",
166168
GOMEMLIMIT: "5GiB",
167169
OPENCLAW_TSGO_PPROF_DIR: "/tmp/profile",
@@ -178,6 +180,7 @@ describe("local-heavy-check-runtime", () => {
178180
"--declaration",
179181
"false",
180182
]);
183+
expect(env.GOMAXPROCS).toBe("3");
181184
expect(env.GOGC).toBe("80");
182185
expect(env.GOMEMLIMIT).toBe("5GiB");
183186
});
@@ -201,6 +204,7 @@ describe("local-heavy-check-runtime", () => {
201204
"--tsBuildInfoFile",
202205
".artifacts/tsgo-cache/root.tsbuildinfo",
203206
]);
207+
expect(env.GOMAXPROCS).toBeUndefined();
204208
expect(env.GOGC).toBeUndefined();
205209
expect(env.GOMEMLIMIT).toBeUndefined();
206210
});
@@ -253,6 +257,7 @@ describe("local-heavy-check-runtime", () => {
253257
"--checkers",
254258
"1",
255259
]);
260+
expect(env.GOMAXPROCS).toBe("1");
256261
expect(env.GOGC).toBe("30");
257262
expect(env.GOMEMLIMIT).toBe("3GiB");
258263
});
@@ -273,6 +278,7 @@ describe("local-heavy-check-runtime", () => {
273278
"--tsBuildInfoFile",
274279
".artifacts/tsgo-cache/root.tsbuildinfo",
275280
]);
281+
expect(env.GOMAXPROCS).toBeUndefined();
276282
expect(env.GOGC).toBeUndefined();
277283
expect(env.GOMEMLIMIT).toBeUndefined();
278284
});

0 commit comments

Comments
 (0)