From: Arran Cudbard-Bell Date: Sat, 23 Sep 2023 04:02:31 +0000 (-0400) Subject: Determine number of workers if value is set to zero X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd8a140938a32bc22a9078ca32bf04d28c743e09;p=thirdparty%2Ffreeradius-server.git Determine number of workers if value is set to zero --- diff --git a/src/lib/server/main_config.c b/src/lib/server/main_config.c index 8fe1c685cdd..8e2deae6180 100644 --- a/src/lib/server/main_config.c +++ b/src/lib/server/main_config.c @@ -421,15 +421,47 @@ static int num_networks_parse(TALLOC_CTX *ctx, void *out, void *parent, return 0; } +static inline CC_HINT(always_inline) +uint32_t num_workers_auto(main_config_t *conf, CONF_ITEM *parent) +{ + uint32_t value; + + value = fr_hw_num_cores_active(); + if (value == 0) { + cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker"); + value = 1; + } + + /* + * If we've got more than four times + * the number of cores as we have + * networks, then set the number of + * workers to the number of cores + * minus networks. + * + * This ensures at a least a 4:1 + * ratio of workers to networks, + * which seems like a sensible ratio. + */ + else if (value > (conf->max_networks * 4)) { + value -= conf->max_networks; + } + + return value; +} + static int num_workers_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, CONF_PARSER const *rule) { int ret; uint32_t value; + main_config_t *conf = parent; if ((ret = cf_pair_parse_value(ctx, out, parent, ci, rule)) < 0) return ret; memcpy(&value, out, sizeof(value)); + if (value == 0) value = num_workers_auto(conf, ci); + /* * If no value is specified, try and * discover it automatically. @@ -448,26 +480,7 @@ static int num_workers_dflt(CONF_PAIR **out, void *parent, CONF_SECTION *cs, fr_ uint32_t value; main_config_t *conf = parent; - value = fr_hw_num_cores_active(); - if (value == 0) { - cf_log_pwarn(parent, "Failed retrieving core count, defaulting to 1 worker"); - value = 1; - } - - /* - * If we've got more than four times - * the number of cores as we have - * networks, then set the number of - * workers to the number of cores - * minus networks. - * - * This ensures at a least a 4:1 - * ratio of workers to networks, - * which seems like a sensible ratio. - */ - else if (value > (conf->max_networks * 4)) { - value -= conf->max_networks; - } + value = num_workers_auto(conf, cf_section_to_item(cs)); strvalue = talloc_asprintf(NULL, "%u", value); *out = cf_pair_alloc(cs, rule->name, strvalue, T_OP_EQ, T_BARE_WORD, quote); talloc_free(strvalue);