]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: global: add a new "thread-groups" directive
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Sep 2021 10:07:23 +0000 (12:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Oct 2021 15:22:26 +0000 (17:22 +0200)
This is used to configure the number of thread groups. For now it can
only be 1.

doc/configuration.txt
include/haproxy/global-t.h
src/cfgparse.c
src/thread.c

index 463b655da480161ac4817aa37155e2e84fbfa765..bc1e0a25f00129125e6fe3602fd0119a6b9bafb8 100644 (file)
@@ -2070,6 +2070,11 @@ stats maxconn <connections>
   By default, the stats socket is limited to 10 concurrent connections. It is
   possible to change this value with "stats maxconn".
 
+thread-groups <number>
+  This setting is only available when support for threads was built in. It
+  makes HAProxy split its threads into <number> independent groups. At the
+  moment, the limit is 1 and is also the default value. See also "nbthread".
+
 uid <number>
   Changes the process's user ID to <number>. It is recommended that the user ID
   is dedicated to HAProxy or to a small set of similar daemons. HAProxy must
index 554d1d9369e68d61e4f5e972e089fafa332354dc..fb01e07687e0d62135e8a76db35b1f5e58d99b15 100644 (file)
@@ -111,7 +111,7 @@ struct global {
        int rlimit_memmax_all;  /* default all-process memory limit in megs ; 0=unset */
        int rlimit_memmax;      /* default per-process memory limit in megs ; 0=unset */
        long maxzlibmem;        /* max RAM for zlib in bytes */
-
+       int nbtgroups;          /* number of thread groups (IDs start at 1) */
        int spread_checks;
        int max_spread_checks;
        int max_syslog_len;
index 7aeffaaf4f656dfcae2f10d1371de1ee6a6b2061..fe498116fcf4163aa433fe78dfd53f5dea738d9c 100644 (file)
@@ -2436,6 +2436,9 @@ int check_config_validity()
 #endif
        }
 
+       if (!global.nbtgroups)
+               global.nbtgroups = 1;
+
        pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED);
 
        pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED);
index 445a73fa8c1cdf509f610fe59115c53d5dc0846d..5788303d0a6ca2ffeb1ae0c40f9ac99ed9361623 100644 (file)
@@ -1035,16 +1035,56 @@ static int cfg_parse_nbthread(char **args, int section_type, struct proxy *curpx
 #endif
 
        HA_DIAG_WARNING_COND(global.nbthread,
-                            "parsing [%s:%d] : nbthread is already defined and will be overridden.\n",
-                            file, line);
+                            "parsing [%s:%d] : '%s' is already defined and will be overridden.\n",
+                            file, line, args[0]);
 
        global.nbthread = nbthread;
        return 0;
 }
 
+/* Parse the "thread-groups" global directive, which takes an integer argument
+ * that contains the desired number of thread groups.
+ */
+static int cfg_parse_thread_groups(char **args, int section_type, struct proxy *curpx,
+                                   const struct proxy *defpx, const char *file, int line,
+                                   char **err)
+{
+       long nbtgroups;
+       char *errptr;
+
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       nbtgroups = strtol(args[1], &errptr, 10);
+       if (!*args[1] || *errptr) {
+               memprintf(err, "'%s' passed a missing or unparsable integer value in '%s'", args[0], args[1]);
+               return -1;
+       }
+
+#ifndef USE_THREAD
+       if (nbtgroups != 1) {
+               memprintf(err, "'%s' specified with a value other than 1 while HAProxy is not compiled with threads support. Please check build options for USE_THREAD", args[0]);
+               return -1;
+       }
+#else
+       if (nbtgroups < 1 || nbtgroups > MAX_TGROUPS) {
+               memprintf(err, "'%s' value must be between 1 and %d (was %ld)", args[0], MAX_TGROUPS, nbtgroups);
+               return -1;
+       }
+#endif
+
+       HA_DIAG_WARNING_COND(global.nbtgroups,
+                            "parsing [%s:%d] : '%s' is already defined and will be overridden.\n",
+                            file, line, args[0]);
+
+       global.nbtgroups = nbtgroups;
+       return 0;
+}
+
 /* config keyword parsers */
 static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_GLOBAL, "nbthread",       cfg_parse_nbthread, 0 },
+       { CFG_GLOBAL, "thread-groups",  cfg_parse_thread_groups, 0 },
        { 0, NULL, NULL }
 }};