Skip to content

Commit 416ca55

Browse files
authored
fix cpu pinning for benchmark env (#1328)
1 parent 2906602 commit 416ca55

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src/components/c2d/compute_engine_docker.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,29 @@ export class C2DEngineDocker extends C2DEngine {
392392
)
393393
}
394394

395+
const physicalCpuCount = this.physicalLimits.get('cpu') || 0
395396
let cpuOffset = 0
396397
for (const env of this.envs) {
397-
const cpuRes = this.getResource(env.resources, 'cpu')
398+
const cpuRes = this.getResource(env.resources ?? [], 'cpu')
398399
if (cpuRes && cpuRes.total > 0) {
399-
const cores = Array.from({ length: cpuRes.total }, (_, i) => cpuOffset + i)
400-
this.envCpuCoresMap.set(env.id, cores)
401-
CORE_LOGGER.info(
402-
`CPU affinity: environment ${env.id} cores ${cores[0]}-${cores[cores.length - 1]} (offset=${cpuOffset}, total=${cpuRes.total})`
400+
const isBenchmarkEnv = env.access?.addresses?.includes(
401+
BENCHMARK_MONITORING_ADDRESS
403402
)
404-
cpuOffset += cpuRes.total
403+
if (isBenchmarkEnv) {
404+
const total = physicalCpuCount > 0 ? physicalCpuCount : cpuRes.total
405+
const cores = Array.from({ length: total }, (_, i) => i)
406+
this.envCpuCoresMap.set(env.id, cores)
407+
CORE_LOGGER.info(
408+
`CPU affinity: benchmark environment ${env.id} cores 0-${cores[cores.length - 1]}`
409+
)
410+
} else {
411+
const cores = Array.from({ length: cpuRes.total }, (_, i) => cpuOffset + i)
412+
this.envCpuCoresMap.set(env.id, cores)
413+
CORE_LOGGER.info(
414+
`CPU affinity: environment ${env.id} cores ${cores[0]}-${cores[cores.length - 1]}`
415+
)
416+
cpuOffset += cpuRes.total
417+
}
405418
}
406419
}
407420

0 commit comments

Comments
 (0)