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.
This commit is contained in:
Rongsong Shen 2026-05-30 01:14:40 +00:00
parent 5f1af48d57
commit c42e1e0cb4
2 changed files with 54 additions and 14 deletions

View file

@ -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);

View file

@ -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 */