]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: do not needlessly set l->maxconn
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Feb 2019 15:49:00 +0000 (16:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 Feb 2019 16:05:32 +0000 (17:05 +0100)
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.

src/cfgparse.c
src/cli.c
src/listener.c
src/peers.c
src/proxy.c
src/stats.c

index 4c8b48b1ed4d39b74fbc0c741f1e55627b18b78a..e29ab9764660a4c3a84e2e8a4d1abcc3f6064cd8 100644 (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;
 
index 9b957186dab9fe5454d008d364b5dfa1f7bb65a1..def5ebacc6780dee4723c78fbfd4f2c07c49c7ef 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -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);
index 4e22e507e858fafbf5df797ce8df22b9de758a06..9a9699c94dbd36b1302c31ce4ee43b921a2b10a2 100644 (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;
        }
 
index dc5bdeaf8d14bb1018e27cfb488581935e02fe3a..743bce88e8ccf774d8daa75799aa147643de46ba 100644 (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;
index 78e099ee98f2ecb469e7ecbed5ecab1f9fa0a120..d3c0698824986de9919bc913d6a002a3ba8e44d4 100644 (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);
        }
index a7c12e1201d83046ff64d4014d2f51c701f52ea6..26b1450e8a497d10c6ce5a29156423d0603b05b8 100644 (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);