MINOR: limits: keep a copy of the rough estimate of needed FDs in global struct

It's always a pain to guess the number of FDs that can be needed by
listeners, checks, threads, pollers etc. We have this estimate in
global.maxsock before calling set_global_maxconn(), but we lose it
the line after. Let's copy it into global.est_fd_usage and keep it.
This will be helpful to try to provide more accurate suggestions for
maxconn.
This commit is contained in:
Willy Tarreau 2025-11-20 08:29:45 +01:00
parent 2c6720a163
commit 91d4f4f618
3 changed files with 8 additions and 10 deletions

View File

@ -233,6 +233,7 @@ struct global {
* than 255 arguments * than 255 arguments
*/ */
/* 2-bytes hole */ /* 2-bytes hole */
int est_fd_usage; /* rough estimate of reserved FDs (listeners, pollers etc) */
int cfg_curr_line; /* line number currently being parsed */ int cfg_curr_line; /* line number currently being parsed */
const char *cfg_curr_file; /* config file currently being parsed or NULL */ const char *cfg_curr_file; /* config file currently being parsed or NULL */
char *cfg_curr_section; /* config section name currently being parsed or NULL */ char *cfg_curr_section; /* config section name currently being parsed or NULL */

View File

@ -2304,6 +2304,9 @@ static void step_init_2(int argc, char** argv)
global.maxsock += p->peers_fe->maxconn; global.maxsock += p->peers_fe->maxconn;
} }
/* count listeners, checks, plus 1 poller and one wake-up pipe (2fd) per thread */
global.est_fd_usage = global.maxsock + 3 * global.nbthread;
/* Compute the global.maxconn and possibly global.maxsslconn values */ /* Compute the global.maxconn and possibly global.maxsslconn values */
set_global_maxconn(); set_global_maxconn();
global.maxsock = compute_ideal_maxsock(global.maxconn); global.maxsock = compute_ideal_maxsock(global.maxconn);

View File

@ -105,9 +105,9 @@ int compute_ideal_maxpipes()
/* considers global.maxsocks, global.maxpipes, async engines, SSL frontends and /* considers global.maxsocks, global.maxpipes, async engines, SSL frontends and
* rlimits and computes an ideal maxconn. It's meant to be called only when * rlimits and computes an ideal maxconn. It's meant to be called only when
* maxsock contains the sum of listening FDs, before it is updated based on * global.est_fd_usage contains the sum of listening FDs, before it is updated
* maxconn and pipes. If there are not enough FDs left, DEFAULT_MAXCONN (by * based on maxconn and pipes. If there are not enough FDs left, DEFAULT_MAXCONN
* default 100) is returned as it is expected that it will even run on tight * (by default 100) is returned as it is expected that it will even run on tight
* environments, and will maintain compatibility with previous packages that * environments, and will maintain compatibility with previous packages that
* used to rely on this value as the default one. The system will emit a * used to rely on this value as the default one. The system will emit a
* warning indicating how many FDs are missing anyway if needed. * warning indicating how many FDs are missing anyway if needed.
@ -162,13 +162,7 @@ static int compute_ideal_maxconn()
} }
/* subtract listeners and checks */ /* subtract listeners and checks */
remain -= global.maxsock; remain -= global.est_fd_usage;
/* one epoll_fd/kqueue_fd per thread */
remain -= global.nbthread;
/* one wake-up pipe (2 fd) per thread */
remain -= 2 * global.nbthread;
/* Fixed pipes values : we only subtract them if they're not larger /* Fixed pipes values : we only subtract them if they're not larger
* than the remaining FDs because pipes are optional. * than the remaining FDs because pipes are optional.