test: relax vitest host throttle on big machines

This commit is contained in:
Peter Steinberger 2026-04-05 11:48:20 +01:00
parent 41d08a6feb
commit 19c081d4a2
No known key found for this signature in database
2 changed files with 22 additions and 23 deletions

View File

@ -107,7 +107,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
"threads",
idleVitestStats,
),
).toBe(1);
).toBe(2);
});
it("caps very large hosts at six local workers", () => {
@ -127,7 +127,7 @@ describe("resolveLocalVitestMaxWorkers", () => {
});
describe("resolveLocalVitestScheduling", () => {
it("falls back to serial when other Vitest workers are already active", () => {
it("scales back to half capacity when other Vitest work is already consuming most cores", () => {
expect(
resolveLocalVitestScheduling(
{},
@ -138,19 +138,19 @@ describe("resolveLocalVitestScheduling", () => {
},
"threads",
{
otherVitestRootCount: 1,
otherVitestWorkerCount: 3,
otherVitestCpuPercent: 120,
otherVitestRootCount: 2,
otherVitestWorkerCount: 12,
otherVitestCpuPercent: 1200,
},
),
).toEqual({
maxWorkers: 1,
fileParallelism: false,
maxWorkers: 4,
fileParallelism: true,
throttledBySystem: true,
});
});
it("caps moderate contention to two workers", () => {
it("keeps big hosts parallel under moderate contention", () => {
expect(
resolveLocalVitestScheduling(
{},
@ -162,12 +162,12 @@ describe("resolveLocalVitestScheduling", () => {
"threads",
{
otherVitestRootCount: 1,
otherVitestWorkerCount: 0,
otherVitestCpuPercent: 10,
otherVitestWorkerCount: 7,
otherVitestCpuPercent: 700,
},
),
).toEqual({
maxWorkers: 2,
maxWorkers: 6,
fileParallelism: true,
throttledBySystem: true,
});

View File

@ -134,28 +134,27 @@ export function resolveLocalVitestScheduling(
};
}
const totalCpuPercentCapacity = Math.max(100, cpuCount * 100);
const otherVitestCpuRatio = processStats.otherVitestCpuPercent / totalCpuPercentCapacity;
const otherVitestWorkerRatio = processStats.otherVitestWorkerCount / cpuCount;
const highSystemContention =
loadRatio >= 1 ||
processStats.otherVitestWorkerCount >= 2 ||
processStats.otherVitestCpuPercent >= 150 ||
processStats.otherVitestRootCount >= 2;
loadRatio >= 1 || otherVitestWorkerRatio >= 0.75 || otherVitestCpuRatio >= 0.75;
if (highSystemContention) {
const maxWorkers = Math.max(1, Math.floor(inferred / 2));
return {
maxWorkers: 1,
fileParallelism: false,
throttledBySystem: true,
maxWorkers,
fileParallelism: maxWorkers > 1,
throttledBySystem: maxWorkers < inferred,
};
}
const moderateSystemContention =
loadRatio >= 0.75 ||
processStats.otherVitestWorkerCount >= 1 ||
processStats.otherVitestCpuPercent >= 75 ||
processStats.otherVitestRootCount >= 1;
loadRatio >= 0.75 || otherVitestWorkerRatio >= 0.4 || otherVitestCpuRatio >= 0.4;
if (moderateSystemContention) {
const maxWorkers = Math.min(inferred, 2);
const maxWorkers = Math.max(2, Math.ceil(inferred * 0.75));
return {
maxWorkers,
fileParallelism: true,