]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: Add nbthread parameter
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Aug 2017 13:37:10 +0000 (15:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 12:58:29 +0000 (13:58 +0100)
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.

doc/configuration.txt
include/types/global.h
src/cfgparse.c
src/haproxy.c

index 59bbc566fe6bb31d6b7faba7d93deeaed300ba56..6f7a99ff612b03906b3103d9be61167654c93048 100644 (file)
@@ -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 <number>
   process, it may be needed to fork multiple daemons. USING MULTIPLE PROCESSES
   IS HARDER TO DEBUG AND IS REALLY DISCOURAGED. See also "daemon".
 
+nbthread <number>
+  This setting is only available when support for threads was built in. It
+  creates <number> threads for each created processes. It means if HAProxy is
+  started in foreground, it only creates <number> 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 <pidfile>
   Writes pids of all daemons into file <pidfile>. This option is equivalent to
   the "-p" command line argument. The file must be accessible to the user
index 205a49497b853e54fb58cbebecc38f4b7d772037..1b2148bf90204d69e9baa75144f303af418ad04a 100644 (file)
@@ -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;
index 4db59a36812ed44103da0d977fe8a58588d3e789..1cb98f354625ae740ef234c9dd37b08e7bb2d737 100644 (file)
@@ -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;
index a4e62a7c278ffd9c9d6e12908b425020b4ddcb9c..bd8dfd629dfbfadc5636c53d5a910aebd4f90ed6 100644 (file)
@@ -77,6 +77,7 @@
 #include <common/time.h>
 #include <common/uri_auth.h>
 #include <common/version.h>
+#include <common/hathreads.h>
 
 #include <types/capture.h>
 #include <types/filters.h>
@@ -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");