]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init: move the maxsock calculation code to compute_ideal_maxsock()
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Mar 2020 16:08:53 +0000 (17:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 10 Mar 2020 17:08:11 +0000 (18:08 +0100)
The maxsock value is currently derived from global.maxconn and a few other
settings, some of which also depend on global.maxconn. This makes it
difficult to check if a limit is already too high or not during the maxconn
automatic sizing.

Let's move this code into a new function, compute_ideal_maxsock() which now
takes a maxconn in argument. It performs the same operations and returns
the maxsock value if global.maxconn were to be set to that value. It now
replaces the previous code to compute maxsock.

src/haproxy.c

index 180dbdb435e8587b6703a5f33168c03055c6fd1d..605e5ee01bd98d07e0c680e3d9cd2ff4b148ea50 100644 (file)
@@ -1555,6 +1555,39 @@ static int compute_ideal_maxconn()
        return MAX(maxconn, DEFAULT_MAXCONN);
 }
 
+/* computes the estimated maxsock value for the given maxconn based on the
+ * possibly set global.maxpipes and existing partial global.maxsock. It may
+ * temporarily change global.maxconn for the time needed to propagate the
+ * computations, and will reset it.
+ */
+static int compute_ideal_maxsock(int maxconn)
+{
+       int maxpipes = global.maxpipes;
+       int maxsock  = global.maxsock;
+
+
+       if (!maxpipes) {
+               int old_maxconn = global.maxconn;
+
+               global.maxconn = maxconn;
+               maxpipes = compute_ideal_maxpipes();
+               global.maxconn = old_maxconn;
+       }
+
+       maxsock += maxconn * 2;         /* each connection needs two sockets */
+       maxsock += maxpipes * 2;        /* each pipe needs two FDs */
+       maxsock += global.nbthread;     /* one epoll_fd/kqueue_fd per thread */
+       maxsock += 2 * global.nbthread; /* one wake-up pipe (2 fd) per thread */
+
+       /* compute fd used by async engines */
+       if (global.ssl_used_async_engines) {
+               int sides = !!global.ssl_used_frontend + !!global.ssl_used_backend;
+
+               maxsock += maxconn * sides * global.ssl_used_async_engines;
+       }
+       return maxsock;
+}
+
 /*
  * This function initializes all the necessary variables. It only returns
  * if everything is OK. If something fails, it exits.
@@ -2233,20 +2266,8 @@ static void init(int argc, char **argv)
                }
        }
 
-       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 */
-       global.maxsock += global.maxpipes * 2; /* each pipe needs two FDs */
-       global.maxsock += global.nbthread;     /* one epoll_fd/kqueue_fd per thread */
-       global.maxsock += 2 * global.nbthread; /* one wake-up pipe (2 fd) per thread */
-
-       /* compute fd used by async engines */
-       if (global.ssl_used_async_engines) {
-               int sides = !!global.ssl_used_frontend + !!global.ssl_used_backend;
-               global.maxsock += global.maxconn * sides * global.ssl_used_async_engines;
-       }
+       global.maxsock = compute_ideal_maxsock(global.maxconn);
+       global.hardmaxconn = global.maxconn;
 
        /* update connection pool thresholds */
        global.tune.pool_low_count  = ((long long)global.maxsock * global.tune.pool_low_ratio  + 99) / 100;