From b3241e3ad7a12e9ab8b18cace4d6da2e3c3396fa Mon Sep 17 00:00:00 2001 From: denisiuriet Date: Wed, 15 Apr 2026 21:55:56 +0300 Subject: [PATCH] fix cpu pinning for benchmark env --- src/components/c2d/compute_engine_docker.ts | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/components/c2d/compute_engine_docker.ts b/src/components/c2d/compute_engine_docker.ts index d24b57492..73c631c26 100755 --- a/src/components/c2d/compute_engine_docker.ts +++ b/src/components/c2d/compute_engine_docker.ts @@ -392,16 +392,29 @@ export class C2DEngineDocker extends C2DEngine { ) } + const physicalCpuCount = this.physicalLimits.get('cpu') || 0 let cpuOffset = 0 for (const env of this.envs) { - const cpuRes = this.getResource(env.resources, 'cpu') + const cpuRes = this.getResource(env.resources ?? [], 'cpu') if (cpuRes && cpuRes.total > 0) { - const cores = Array.from({ length: cpuRes.total }, (_, i) => cpuOffset + i) - this.envCpuCoresMap.set(env.id, cores) - CORE_LOGGER.info( - `CPU affinity: environment ${env.id} cores ${cores[0]}-${cores[cores.length - 1]} (offset=${cpuOffset}, total=${cpuRes.total})` + const isBenchmarkEnv = env.access?.addresses?.includes( + BENCHMARK_MONITORING_ADDRESS ) - cpuOffset += cpuRes.total + if (isBenchmarkEnv) { + const total = physicalCpuCount > 0 ? physicalCpuCount : cpuRes.total + const cores = Array.from({ length: total }, (_, i) => i) + this.envCpuCoresMap.set(env.id, cores) + CORE_LOGGER.info( + `CPU affinity: benchmark environment ${env.id} cores 0-${cores[cores.length - 1]}` + ) + } else { + const cores = Array.from({ length: cpuRes.total }, (_, i) => cpuOffset + i) + this.envCpuCoresMap.set(env.id, cores) + CORE_LOGGER.info( + `CPU affinity: environment ${env.id} cores ${cores[0]}-${cores[cores.length - 1]}` + ) + cpuOffset += cpuRes.total + } } }