From: Christopher Faulet Date: Tue, 29 Aug 2017 13:37:10 +0000 (+0200) Subject: MINOR: threads: Add nbthread parameter X-Git-Tag: v1.8-rc1~165 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be0faa2e47939e2672266a1a23b8a6de542b520e;p=thirdparty%2Fhaproxy.git MINOR: threads: Add nbthread parameter It is only parsed and initialized for now. It will be used later. This parameter is only available when support for threads was built in. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 59bbc566fe..6f7a99ff61 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -542,6 +542,7 @@ The following keywords are supported in the "global" section : - log-send-hostname - lua-load - nbproc + - nbthread - node - pidfile - presetenv @@ -826,6 +827,13 @@ nbproc process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon". +nbthread + This setting is only available when support for threads was built in. It + creates threads for each created processes. It means if HAProxy is + started in foreground, it only creates threads for the first + process. FOR NOW, THREADS SUPPORT IN HAPROXY IS HIGHLY EXPERIMENTAL AND IT + MUST BE ENABLED WITH CAUTION AND AT YOUR OWN RISK. See also "nbproc". + pidfile Writes pids of all daemons into file . This option is equivalent to the "-p" command line argument. The file must be accessible to the user diff --git a/include/types/global.h b/include/types/global.h index 205a49497b..1b2148bf90 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -86,6 +86,7 @@ struct global { int gid; int external_check; int nbproc; + int nbthread; unsigned int hard_stop_after; /* maximum time allowed to perform a soft-stop */ int maxconn, hardmaxconn; int maxsslconn; diff --git a/src/cfgparse.c b/src/cfgparse.c index 4db59a3681..1cb98f3546 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1041,6 +1041,30 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) goto out; } } + else if (!strcmp(args[0], "nbthread")) { + if (alertif_too_many_args(1, file, linenum, args, &err_code)) + goto out; + if (*(args[1]) == 0) { + Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + global.nbthread = atol(args[1]); + if (global.nbthread < 1 || global.nbthread > LONGBITS) { + Alert("parsing [%s:%d] : '%s' must be between 1 and %d (was %d).\n", + file, linenum, args[0], LONGBITS, global.nbthread); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } +#ifndef USE_THREAD + if (global.nbthread > 1) { + Alert("HAProxy is not compiled with threads support, please check build options for USE_THREAD.\n"); + global.nbthread = 1; + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } +#endif + } else if (!strcmp(args[0], "maxconn")) { if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; diff --git a/src/haproxy.c b/src/haproxy.c index a4e62a7c27..bd8dfd629d 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -77,6 +77,7 @@ #include #include #include +#include #include #include @@ -122,6 +123,7 @@ int relative_pid = 1; /* process id starting at 1 */ struct global global = { .hard_stop_after = TICK_ETERNITY, .nbproc = 1, + .nbthread = 1, .req_count = 0, .logsrvs = LIST_HEAD_INIT(global.logsrvs), .maxzlibmem = 0, @@ -1754,6 +1756,9 @@ static void init(int argc, char **argv) if (global.nbproc < 1) global.nbproc = 1; + if (global.nbthread < 1) + global.nbthread = 1; + /* Realloc trash buffers because global.tune.bufsize may have changed */ if (!init_trash_buffers()) { Alert("failed to initialize trash buffers.\n");