MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_default_worker_count

Function cbm_default_worker_count

src/foundation/system_info.c:283–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283int cbm_default_worker_count(bool initial) {
284 /* CBM_WORKERS env override (clamped to [1, CBM_WORKERS_MAX]).
285 * Useful inside containers where sysconf(_SC_NPROCESSORS_ONLN)
286 * reports host CPUs rather than the cgroup's effective CPU quota.
287 * Same precedence shape as other CBM_* env overrides:
288 * explicit override > implicit detection. */
289 char buf[CBM_SZ_32];
290 if (cbm_safe_getenv("CBM_WORKERS", buf, sizeof(buf), NULL) != NULL) {
291 long n = strtol(buf, NULL, CBM_DECIMAL_BASE);
292 if (n >= MIN_WORKERS && n <= CBM_WORKERS_MAX) {
293 return (int)n;
294 }
295 cbm_log_warn("workers.env.invalid", "value", buf, "fallback", "sysconf");
296 }
297
298 cbm_system_info_t info = cbm_system_info();
299 if (initial) {
300 /* Use all cores for initial indexing — user is waiting */
301 return info.total_cores;
302 }
303 /* Incremental: leave headroom for user's apps */
304 int workers = info.perf_cores - SKIP_ONE;
305 return workers > 0 ? workers : MIN_WORKERS;
306}

Callers 12

cbm_sem_corpus_finalizeFunction · 0.85
cbm_parallel_forFunction · 0.85
run_extract_resolveFunction · 0.85
closure_probe_surfacesFunction · 0.85
run_closure_deltaFunction · 0.85
effective_worker_countFunction · 0.85
test_platform.cFile · 0.85
test_worker_pool.cFile · 0.85

Calls 2

cbm_safe_getenvFunction · 0.85
cbm_system_infoFunction · 0.85

Tested by

no test coverage detected