mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-29 08:02:08 +00:00
MINOR: init: move the maxsock calculation code to compute_ideal_maxsock()
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.
This commit is contained in:
parent
1d117e3dcd
commit
a409f30d09
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user