]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init: make the maxpipe computation more accurate
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Mar 2019 13:19:31 +0000 (14:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Mar 2019 14:53:14 +0000 (15:53 +0100)
The default number of pipes is adjusted based on the sum of frontends
and backends maxconn/fullconn settings. Now that it is possible to have
a null maxconn on a frontend to indicate "unlimited" with commit
c8d5b95e6 ("MEDIUM: config: don't enforce a low frontend maxconn value
anymore"), the sum of maxconn may remain low and limited to the only
frontends/backends where this limit is set.

This patch considers this new unlimited case when doing the check, and
automatically switches to the default value which is maxconn/4 in this
case. All the calculation was moved to a distinct function for ease of
use. This function also supports returning unlimited (-1) when the
value depends on global.maxconn and this latter is not yet set.

src/haproxy.c

index 40865f0a36408d3fb68cd368dca532434c6e76a7..21bfcbd97aa5f34016d31a95087b9134ec5c1ec5 100644 (file)
@@ -1402,6 +1402,53 @@ static char **copy_argv(int argc, char **argv)
        return newargv;
 }
 
+/* considers splicing proxies' maxconn, computes the ideal global.maxpipes
+ * setting, and returns it. It may return -1 meaning "unlimited" if some
+ * unlimited proxies have been found and the global.maxconn value is not yet
+ * set. It may also return a value greater than maxconn if it's not yet set.
+ * Note that a value of zero means there is no need for pipes. -1 is never
+ * returned if global.maxconn is valid.
+ */
+static int compute_ideal_maxpipes()
+{
+       struct proxy *cur;
+       int nbfe = 0, nbbe = 0;
+       int unlimited = 0;
+       int pipes;
+       int max;
+
+       for (cur = proxies_list; cur; cur = cur->next) {
+               if (cur->options2 & (PR_O2_SPLIC_ANY)) {
+                       if (cur->cap & PR_CAP_FE) {
+                               max = cur->maxconn;
+                               nbfe += max;
+                               if (!max) {
+                                       unlimited = 1;
+                                       break;
+                               }
+                       }
+                       if (cur->cap & PR_CAP_BE) {
+                               max = cur->fullconn ? cur->fullconn : global.maxconn;
+                               nbbe += max;
+                               if (!max) {
+                                       unlimited = 1;
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       pipes = MAX(nbfe, nbbe);
+       if (global.maxconn) {
+               if (pipes > global.maxconn || unlimited)
+                       pipes = global.maxconn;
+       } else if (unlimited) {
+               pipes = -1;
+       }
+
+       return pipes >= 4 ? pipes / 4 : pipes;
+}
+
 /*
  * This function initializes all the necessary variables. It only returns
  * if everything is OK. If something fails, it exits.
@@ -2039,27 +2086,8 @@ static void init(int argc, char **argv)
                }
        }
 
-       if (!global.maxpipes) {
-               /* maxpipes not specified. Count how many frontends and backends
-                * may be using splicing, and bound that to maxconn.
-                */
-               struct proxy *cur;
-               int nbfe = 0, nbbe = 0;
-
-               for (cur = proxies_list; cur; cur = cur->next) {
-                       if (cur->options2 & (PR_O2_SPLIC_ANY)) {
-                               if (cur->cap & PR_CAP_FE)
-                                       nbfe += cur->maxconn;
-                               if (cur->cap & PR_CAP_BE)
-                                       nbbe += cur->fullconn ? cur->fullconn : global.maxconn;
-                       }
-               }
-               global.maxpipes = MAX(nbfe, nbbe);
-               if (global.maxpipes > global.maxconn)
-                       global.maxpipes = global.maxconn;
-               global.maxpipes /= 4;
-       }
-
+       if (!global.maxpipes)
+               global.maxpipes = compute_ideal_maxpipes();
 
        global.hardmaxconn = global.maxconn;  /* keep this max value */
        global.maxsock += global.maxconn * 2; /* each connection needs two sockets */