From c42e1e0cb4e52a9393532e05649c9bb8a6e39475 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Sat, 30 May 2026 01:14:40 +0000 Subject: [PATCH] refactor(controller): extract init_controller_tunables() for perf params Add ctrl_tunables struct to cluster_t with per-table fields: jobmgr_nhash/delta, workermgr_nhash/delta, qmgr_nhash/delta, resmgr_nhash/delta/inst, xstrings_nhash init_controller_tunables() sets defaults (jobs=512, others=128) and is called from cluster_init_phase1 so values are available before cluster_init_phase2. Phase2 reads from c->tunables instead of cluster_config or local #defines. Each table gets its own values since they hold different item counts: jobs can scale to hundreds, workers/queues/resources are typically single-digit to tens. --- src/controller/cluster.c | 52 +++++++++++++++++++++++++---------- src/include/xce/cluster_def.h | 16 +++++++++++ 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/controller/cluster.c b/src/controller/cluster.c index bbe45a32..d91c2503 100644 --- a/src/controller/cluster.c +++ b/src/controller/cluster.c @@ -647,6 +647,32 @@ static void config_obj_killer(void* arg) } } +/* + * init_controller_tunables: set performance-tuning defaults on c->tunables. + * + * Called early in cluster_init_phase1 so the values are available throughout + * the startup sequence (including pre-election and phase2). + * + * TODO: wire these to cluster_config fields once the config generation tool + * supports jobmgr/workermgr/qmgr/resmgr/xstrings (@13–@17). + */ +static void init_controller_tunables(cluster_t *c) +{ + /* Jobs can be numerous; workers/queues/resources are typically smaller. + * TODO: replace with config-driven values once the config generation tool + * supports cluster_config fields @13–@17 (jobmgr/workermgr/qmgr/resmgr/xstrings). */ + c->tunables.jobmgr_nhash = 512; + c->tunables.jobmgr_delta = 128; + c->tunables.workermgr_nhash = 128; + c->tunables.workermgr_delta = 32; + c->tunables.qmgr_nhash = 128; + c->tunables.qmgr_delta = 32; + c->tunables.resmgr_nhash = 128; + c->tunables.resmgr_delta = 32; + c->tunables.resmgr_inst = 64; + c->tunables.xstrings_nhash = 512; +} + int cluster_init_phase1(cluster_t* c) { int rc; @@ -728,6 +754,8 @@ int cluster_init_phase1(cluster_t* c) * cluster_open_listener() uses this for its idempotency guard. */ c->ep.fd = -1; + init_controller_tunables(c); + return 0; } @@ -820,23 +848,19 @@ int cluster_init_phase2(cluster_t* c) mylock_init(&(c->sched.lock)); c->sched.ep = NULL; - /* TODO: replace with config-driven values once config generation tool is ready */ -#define CTRL_PERF_NHASH 512 -#define CTRL_PERF_DELTA 64 -#define CTRL_PERF_INST 64 - resmgr_params.nslots = CTRL_PERF_NHASH; - resmgr_params.delta = CTRL_PERF_DELTA; - jobmgr_params.nslots = CTRL_PERF_NHASH; - jobmgr_params.delta = CTRL_PERF_DELTA; - workermgr_params.nslots = CTRL_PERF_NHASH; - workermgr_params.delta = CTRL_PERF_DELTA; - qmgr_params.nslots = CTRL_PERF_NHASH; - qmgr_params.delta = CTRL_PERF_DELTA; + resmgr_params.nslots = c->tunables.resmgr_nhash; + resmgr_params.delta = c->tunables.resmgr_delta; + jobmgr_params.nslots = c->tunables.jobmgr_nhash; + jobmgr_params.delta = c->tunables.jobmgr_delta; + workermgr_params.nslots = c->tunables.workermgr_nhash; + workermgr_params.delta = c->tunables.workermgr_delta; + qmgr_params.nslots = c->tunables.qmgr_nhash; + qmgr_params.delta = c->tunables.qmgr_delta; c->configmgr = makeInstance(&xkvmgr_type, &config_mgr_params); c->jobmgr = makeInstance(&xkvmgr_type, &jobmgr_params); c->resmgr = makeInstance(&xkvmgr_type, &resmgr_params); - zarray_init(&(c->sharedinst), CTRL_PERF_INST, + zarray_init(&(c->sharedinst), c->tunables.resmgr_inst, (zarray_item_killer_t)resval_obj_killer); c->workermgr = makeInstance(&xkvmgr_type, &workermgr_params); c->qmgr = makeInstance(&xkvmgr_type, &qmgr_params); @@ -852,7 +876,7 @@ int cluster_init_phase2(cluster_t* c) iomgr_set_ssl_ctx(&(c->iomgr), ssl_ctx); } - xstring_table_init(CTRL_PERF_NHASH); + xstring_table_init(c->tunables.xstrings_nhash); job_obj_init(5381, 5381); zarray_init(&(c->endpoints), 16, endpoint_killer); diff --git a/src/include/xce/cluster_def.h b/src/include/xce/cluster_def.h index 67562637..cfd3e9a1 100644 --- a/src/include/xce/cluster_def.h +++ b/src/include/xce/cluster_def.h @@ -124,6 +124,22 @@ typedef struct cluster_s { pthread_t heartbeat_listener_tid; /* pre-Phase-2 SSL listener thread */ _Atomic int heartbeat_listener_running; _Atomic int lost_and_found_job_count; /* incremented during persist_recover() */ + + /* Performance-tuning parameters — initialized by init_controller_tunables() + * in cluster_init_phase1 so they are available before cluster_init_phase2. + * TODO: wire to cluster_config once config generation tool supports @13-@17. */ + struct { + int jobmgr_nhash; /* hash slots for job table */ + int jobmgr_delta; /* growth step for job table */ + int workermgr_nhash; /* hash slots for worker table */ + int workermgr_delta; /* growth step for worker table */ + int qmgr_nhash; /* hash slots for queue table */ + int qmgr_delta; /* growth step for queue table */ + int resmgr_nhash; /* hash slots for resource table */ + int resmgr_delta; /* growth step for resource table */ + int resmgr_inst; /* growth step for shared-instance array */ + int xstrings_nhash; /* hash slots for xstring table */ + } tunables; } cluster_t; #endif /* XCE_CLUSTER_DEF_H */