From a9e9ade846e7f503c80af874be640ca7379d3edc Mon Sep 17 00:00:00 2001 From: reshke Date: Thu, 20 May 2021 17:26:19 +0500 Subject: [PATCH] autoconfigure number of workers --- odyssey-dev.conf | 4 ++-- sources/config_reader.c | 25 +++++++++++++++++++++---- sources/odyssey.h | 1 + sources/sysv.h | 12 ++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 sources/sysv.h diff --git a/odyssey-dev.conf b/odyssey-dev.conf index f00cc2f4..e43ebfa1 100644 --- a/odyssey-dev.conf +++ b/odyssey-dev.conf @@ -19,7 +19,7 @@ log_query yes log_stats yes stats_interval 60 -workers 2 +workers "auto" resolvers 1 readahead 8192 @@ -175,7 +175,7 @@ database "postgres2" { log_debug no ldap_endpoint_name "ldap1" - enable_password_passthrough "yes" + password_passthrough yes quantiles "0.99,0.95,0.5" client_max 107 diff --git a/sources/config_reader.c b/sources/config_reader.c index 17181c53..a4480455 100644 --- a/sources/config_reader.c +++ b/sources/config_reader.c @@ -1541,12 +1541,29 @@ static int od_config_reader_parse(od_config_reader_t *reader, } continue; /* workers */ - case OD_LWORKERS: - if (!od_config_reader_number(reader, - &config->workers)) { + case OD_LWORKERS: { + od_token_t tok; + int rc; + rc = od_parser_next(&reader->parser, &tok); + switch (rc) { + case OD_PARSER_NUM: { + config->workers = tok.value.num; + } break; + case OD_PARSER_STRING: { + if (strncmp(tok.value.string.pointer, "auto", + tok.value.string.size) == 0) { + config->workers = + (1 + od_get_ncpu()) >> 1; + break; + } /* else fallthrough default*/ + } + default: + od_config_reader_error( + reader, &tok, + "expected 'number' or '\"auto\"'"); goto error; } - + } continue; /* resolvers */ case OD_LRESOLVERS: diff --git a/sources/odyssey.h b/sources/odyssey.h index 2a9f7741..63af905b 100644 --- a/sources/odyssey.h +++ b/sources/odyssey.h @@ -18,6 +18,7 @@ #include "sources/macro.h" #include "sources/build.h" #include "sources/atomic.h" +#include "sources/sysv.h" #include "sources/util.h" #include "sources/debugprintf.h" diff --git a/sources/sysv.h b/sources/sysv.h new file mode 100644 index 00000000..c7700551 --- /dev/null +++ b/sources/sysv.h @@ -0,0 +1,12 @@ +#ifndef ODYSSEY_SYSV_H +#define ODYSSEY_SYSV_H + +static inline size_t od_get_ncpu() +{ +#ifdef _SC_NPROCESSORS_ONLN + return sysconf(_SC_NPROCESSORS_ONLN); +#endif + return 1; +} + +#endif /* ODYSSEY_SYSV_H */