Skip to content

Commit 3be45dc

Browse files
committed
remove cpu cores from config
1 parent c1bbd3a commit 3be45dc

4 files changed

Lines changed: 16 additions & 28 deletions

File tree

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ export P2P_FILTER_ANNOUNCED_ADDRESSES=
6969
# CPU, RAM, and disk are per-env exclusive: inUse tracked only within the environment where the job runs.
7070
# A global check ensures the aggregate usage across all environments does not exceed physical capacity.
7171
# GPUs are shared-exclusive: if a job on envA uses gpu0, it shows as in-use on envB too.
72-
# CPU cores can be hard-partitioned per environment via cpuCores (e.g., envA gets cores 0-3, envB gets 4-7).
72+
# CPU cores are automatically partitioned across environments based on each env's cpu.total.
7373
# CPU and RAM defaults are auto-detected from the system when not configured.
74-
# export DOCKER_COMPUTE_ENVIRONMENTS='[{"socketPath":"/var/run/docker.sock","environments":[{"id":"envA","cpuCores":[0,1,2,3],"storageExpiry":604800,"maxJobDuration":3600,"minJobDuration":60,"resources":[{"id":"cpu","total":4,"max":4,"min":1,"type":"cpu"},{"id":"ram","total":16,"max":16,"min":1,"type":"ram"},{"id":"disk","total":500,"max":500,"min":10,"type":"disk"},{"id":"gpu0","total":1,"max":1,"min":0,"type":"gpu","init":{"deviceRequests":{"Driver":"nvidia","DeviceIDs":["0"],"Capabilities":[["gpu"]]}}}],"fees":{"1":[{"feeToken":"0x123","prices":[{"id":"cpu","price":1},{"id":"ram","price":0.1},{"id":"disk","price":0.01},{"id":"gpu0","price":5}]}]}}]}]'
74+
# export DOCKER_COMPUTE_ENVIRONMENTS='[{"socketPath":"/var/run/docker.sock","environments":[{"id":"envA","storageExpiry":604800,"maxJobDuration":3600,"minJobDuration":60,"resources":[{"id":"cpu","total":4,"max":4,"min":1,"type":"cpu"},{"id":"ram","total":16,"max":16,"min":1,"type":"ram"},{"id":"disk","total":500,"max":500,"min":10,"type":"disk"},{"id":"gpu0","total":1,"max":1,"min":0,"type":"gpu","init":{"deviceRequests":{"Driver":"nvidia","DeviceIDs":["0"],"Capabilities":[["gpu"]]}}}],"fees":{"1":[{"feeToken":"0x123","prices":[{"id":"cpu","price":1},{"id":"ram","price":0.1},{"id":"disk","price":0.01},{"id":"gpu0","price":5}]}]}}]}]'
7575
export DOCKER_COMPUTE_ENVIRONMENTS=
7676

7777

src/@types/C2D/C2D.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export interface C2DEnvironmentConfig {
150150
access?: ComputeAccessList
151151
free?: ComputeEnvironmentFreeOptions
152152
resources?: ComputeResource[]
153-
cpuCores?: number[] // explicit physical CPU core indices for this environment
154153
}
155154

156155
export interface C2DDockerConfig {

src/components/c2d/compute_engine_docker.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,25 @@ export class C2DEngineDocker extends C2DEngine {
272272
'-' +
273273
create256Hash(JSON.stringify(env.fees) + envIdSuffix)
274274

275-
// Per-environment CPU core affinity
276-
if (envDef.cpuCores && envDef.cpuCores.length > 0) {
277-
this.envCpuCoresMap.set(env.id, envDef.cpuCores)
278-
CORE_LOGGER.info(
279-
`CPU affinity: environment ${env.id} cores [${envDef.cpuCores.join(',')}]`
280-
)
281-
}
282-
283275
this.envs.push(env)
284276
CORE_LOGGER.info(
285277
`Engine ${this.getC2DConfig().hash}: created environment ${env.id} (index=${envIdx}, resources=${envResources.map((r) => r.id).join(',')})`
286278
)
287279
}
288280

281+
let cpuOffset = 0
282+
for (const env of this.envs) {
283+
const cpuRes = this.getResource(env.resources, 'cpu')
284+
if (cpuRes && cpuRes.total > 0) {
285+
const cores = Array.from({ length: cpuRes.total }, (_, i) => cpuOffset + i)
286+
this.envCpuCoresMap.set(env.id, cores)
287+
CORE_LOGGER.info(
288+
`CPU affinity: environment ${env.id} cores ${cores[0]}-${cores[cores.length - 1]} (offset=${cpuOffset}, total=${cpuRes.total})`
289+
)
290+
cpuOffset += cpuRes.total
291+
}
292+
}
293+
289294
// Rebuild CPU allocations from running containers (handles node restart)
290295
await this.rebuildCpuAllocations()
291296

src/utils/config/schemas.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ export const C2DEnvironmentConfigSchema = z
175175
})
176176
.optional(),
177177
free: ComputeEnvironmentFreeOptionsSchema.optional(),
178-
resources: z.array(ComputeResourceSchema).optional(),
179-
cpuCores: z.array(z.number().int().min(0)).optional()
178+
resources: z.array(ComputeResourceSchema).optional()
180179
})
181180
.refine(
182181
(data) =>
@@ -206,21 +205,6 @@ export const C2DDockerConfigSchema = z.array(
206205
paymentClaimInterval: z.number().int().optional(),
207206
environments: z.array(C2DEnvironmentConfigSchema).min(1)
208207
})
209-
.refine(
210-
(data) => {
211-
// CPU core assignments must not overlap across environments
212-
const seenCores = new Set<number>()
213-
for (const env of data.environments) {
214-
if (!env.cpuCores) continue
215-
for (const core of env.cpuCores) {
216-
if (seenCores.has(core)) return false
217-
seenCores.add(core)
218-
}
219-
}
220-
return true
221-
},
222-
{ message: 'CPU core assignments must not overlap across environments' }
223-
)
224208
)
225209

226210
export const C2DClusterInfoSchema = z.object({

0 commit comments

Comments
 (0)