MINOR: listener: do not needlessly set l->maxconn

It's pointless to always set and maintain l->maxconn because the accept
loop already enforces the frontend's limit anyway. Thus let's stop setting
this value by default and keep it to zero meaning "no limit". This way the
frontend's maxconn will be used by default. Of course if a value is set,
it will be enforced.
This commit is contained in:
Willy Tarreau 2019-02-27 16:49:00 +01:00
parent e2711c7bd6
commit a8cf66bcab
6 changed files with 10 additions and 19 deletions

View File

@ -649,7 +649,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
}
l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
l->maxaccept = 1;
l->maxconn = curpeers->peers_fe->maxconn;
l->accept = session_accept_fd;
l->analysers |= curpeers->peers_fe->fe_req_ana;
l->default_target = curpeers->peers_fe->default_target;
@ -852,7 +851,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
l->maxaccept = 1;
l->maxconn = curpeers->peers_fe->maxconn;
l->accept = session_accept_fd;
l->analysers |= curpeers->peers_fe->fe_req_ana;
l->default_target = curpeers->peers_fe->default_target;
@ -3739,8 +3737,6 @@ out_uri_auth_compat:
if (curproxy->options & PR_O_TCP_NOLING)
listener->options |= LI_O_NOLINGER;
if (!listener->maxconn)
listener->maxconn = curproxy->maxconn;
if (!listener->maxaccept)
listener->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : 64;

View File

@ -297,7 +297,6 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
}
list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->maxconn = global.stats_fe->maxconn;
l->accept = session_accept_fd;
l->default_target = global.stats_fe->default_target;
l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */
@ -2520,7 +2519,6 @@ int mworker_cli_proxy_new_listener(char *line)
list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->maxconn = 10;
l->accept = session_accept_fd;
l->default_target = mworker_proxy->default_target;
/* don't make the peers subject to global limits and don't close it in the master */
@ -2589,7 +2587,6 @@ int mworker_cli_sockpair_new(struct mworker_proc *mworker_proc, int proc)
path = NULL;
list_for_each_entry(l, &bind_conf->listeners, by_bind) {
l->maxconn = global.stats_fe->maxconn;
l->accept = session_accept_fd;
l->default_target = global.stats_fe->default_target;
l->options |= (LI_O_UNLIMITED | LI_O_NOSTOP);

View File

@ -234,7 +234,7 @@ static void enable_listener(struct listener *listener)
listener->state = LI_LISTEN;
}
}
else if (listener->nbconn < listener->maxconn) {
else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
fd_want_recv(listener->fd);
listener->state = LI_READY;
}
@ -360,7 +360,7 @@ int resume_listener(struct listener *l)
LIST_DEL_LOCKED(&l->wait_queue);
if (l->nbconn >= l->maxconn) {
if (l->maxconn && l->nbconn >= l->maxconn) {
l->state = LI_FULL;
goto end;
}
@ -682,7 +682,7 @@ void listener_accept(int fd)
*/
do {
count = l->nbconn;
if (count >= l->maxconn) {
if (l->maxconn && count >= l->maxconn) {
/* the listener was marked full or another
* thread is going to do it.
*/
@ -692,7 +692,7 @@ void listener_accept(int fd)
next_conn = count + 1;
} while (!HA_ATOMIC_CAS(&l->nbconn, &count, next_conn));
if (next_conn == l->maxconn) {
if (l->maxconn && next_conn == l->maxconn) {
/* we filled it, mark it full */
listener_full(l);
}
@ -942,7 +942,7 @@ void listener_accept(int fd)
if (next_actconn)
HA_ATOMIC_SUB(&actconn, 1);
if ((l->state == LI_FULL && l->nbconn < l->maxconn) ||
if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
(l->state == LI_LIMITED && ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn)))) {
/* at least one thread has to this when quitting */
resume_listener(l);
@ -1212,8 +1212,8 @@ static int bind_parse_maxconn(char **args, int cur_arg, struct proxy *px, struct
}
val = atol(args[cur_arg + 1]);
if (val <= 0) {
memprintf(err, "'%s' : invalid value %d, must be > 0", args[cur_arg], val);
if (val < 0) {
memprintf(err, "'%s' : invalid value %d, must be >= 0", args[cur_arg], val);
return ERR_ALERT | ERR_FATAL;
}

View File

@ -2551,14 +2551,11 @@ static struct task *process_peer_sync(struct task * task, void *context, unsigne
int peers_init_sync(struct peers *peers)
{
struct peer * curpeer;
struct listener *listener;
for (curpeer = peers->remote; curpeer; curpeer = curpeer->next) {
peers->peers_fe->maxconn += 3;
}
list_for_each_entry(listener, &peers->peers_fe->conf.listeners, by_fe)
listener->maxconn = peers->peers_fe->maxconn;
peers->sync_task = task_new(MAX_THREADS_MASK);
if (!peers->sync_task)
return 0;

View File

@ -1884,7 +1884,8 @@ static int cli_parse_set_maxconn_frontend(char **args, char *payload, struct app
px->maxconn = v;
list_for_each_entry(l, &px->conf.listeners, by_fe) {
l->maxconn = v;
if (l->maxconn)
l->maxconn = v;
if (l->state == LI_FULL)
resume_listener(l);
}

View File

@ -1472,7 +1472,7 @@ int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req);
stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn);
stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess);
stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
stats[ST_F_STATUS] = mkf_str(FO_STATUS, (!l->maxconn || l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid);