]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: move the maxconn parameter to the bind_conf
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Jan 2023 17:59:37 +0000 (18:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Feb 2023 17:00:20 +0000 (18:00 +0100)
The maxconn is set per bind line so let's move it there. This might
possibly even slightly reduce inter-thread contention since this one
is read-mostly and it was stored next to nbconn which changes for
each connection setup or teardown.

include/haproxy/listener-t.h
src/listener.c
src/stats.c

index 413d84b9699e1cf25a5602b3a4ed301b05ad29a0..4ff43c095e5291c817d2ea56213ad453491e45c6 100644 (file)
@@ -202,6 +202,7 @@ struct bind_conf {
        int tcp_ut;                /* for TCP, user timeout */
        int maxaccept;             /* if set, max number of connections accepted at once (-1 when disabled) */
        unsigned int backlog;      /* if set, listen backlog */
+       int maxconn;               /* maximum connections allowed on this listener */
        int level;                 /* stats access level (ACCESS_LVL_*) */
        int severity_output;       /* default severity output format in cli feedback messages */
        struct list listeners;     /* list of listeners using this bind config */
@@ -243,7 +244,6 @@ struct listener {
 
        struct fe_counters *counters;   /* statistics counters */
        int nbconn;                     /* current number of connections on this listener */
-       int maxconn;                    /* maximum connections allowed on this listener */
        int (*accept)(struct connection *conn); /* upper layer's accept() */
        enum obj_type *default_target;  /* default target to use for accepted sessions or NULL */
        /* cache line boundary */
index 18c08a8f664bd88b2f417306c3a4a13fcacf240e..0a44b1bba76de8df1803914dfd4fa8c76d3009cd 100644 (file)
@@ -229,7 +229,7 @@ int li_init_per_thr(struct listener *li)
 /* helper to get listener status for stats */
 enum li_status get_li_status(struct listener *l)
 {
-       if (!l->maxconn || l->nbconn < l->maxconn) {
+       if (!l->bind_conf->maxconn || l->nbconn < l->bind_conf->maxconn) {
                if (l->state == LI_LIMITED)
                        return LI_STATUS_WAITING;
                else
@@ -319,7 +319,7 @@ void enable_listener(struct listener *listener)
                         */
                        do_unbind_listener(listener);
                }
-               else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
+               else if (!listener->bind_conf->maxconn || listener->nbconn < listener->bind_conf->maxconn) {
                        listener->rx.proto->enable(listener);
                        listener_set_state(listener, LI_READY);
                }
@@ -537,7 +537,7 @@ int resume_listener(struct listener *l, int lpx)
        if (l->rx.proto->resume)
                ret = l->rx.proto->resume(l);
 
-       if (l->maxconn && l->nbconn >= l->maxconn) {
+       if (l->bind_conf->maxconn && l->nbconn >= l->bind_conf->maxconn) {
                l->rx.proto->disable(l);
                listener_set_state(l, LI_FULL);
                goto done;
@@ -816,8 +816,8 @@ int listener_backlog(const struct listener *l)
        if (l->bind_conf->frontend->backlog)
                return l->bind_conf->frontend->backlog;
 
-       if (l->maxconn)
-               return l->maxconn;
+       if (l->bind_conf->maxconn)
+               return l->bind_conf->maxconn;
 
        if (l->bind_conf->frontend->maxconn)
                return l->bind_conf->frontend->maxconn;
@@ -916,7 +916,7 @@ void listener_accept(struct listener *l)
                 */
                do {
                        count = l->nbconn;
-                       if (unlikely(l->maxconn && count >= l->maxconn)) {
+                       if (unlikely(l->bind_conf->maxconn && count >= l->bind_conf->maxconn)) {
                                /* the listener was marked full or another
                                 * thread is going to do it.
                                 */
@@ -1178,7 +1178,7 @@ void listener_accept(struct listener *l)
        if (next_actconn)
                _HA_ATOMIC_DEC(&actconn);
 
-       if ((l->state == LI_FULL && (!l->maxconn || l->nbconn < l->maxconn)) ||
+       if ((l->state == LI_FULL && (!l->bind_conf->maxconn || l->nbconn < l->bind_conf->maxconn)) ||
            (l->state == LI_LIMITED &&
             ((!p || p->feconn < p->maxconn) && (actconn < global.maxconn) &&
              (!tick_isset(global_listener_queue_task->expire) ||
@@ -1704,7 +1704,6 @@ int bind_parse_args_list(struct bind_conf *bind_conf, char **args, int cur_arg,
 /* parse the "maxconn" bind keyword */
 static int bind_parse_maxconn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
 {
-       struct listener *l;
        int val;
 
        if (!*args[cur_arg + 1]) {
@@ -1718,9 +1717,7 @@ static int bind_parse_maxconn(char **args, int cur_arg, struct proxy *px, struct
                return ERR_ALERT | ERR_FATAL;
        }
 
-       list_for_each_entry(l, &conf->listeners, by_bind)
-               l->maxconn = val;
-
+       conf->maxconn = val;
        return 0;
 }
 
index 4a1dca2f214a8b32b5b9c3726e0caabb870847fe..791b7927976ebfe4ceef9e9791da7a4a44e79d59 100644 (file)
@@ -1996,7 +1996,7 @@ int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
                                metric = mkf_u32(FN_MAX, l->counters->conn_max);
                                break;
                        case ST_F_SLIM:
-                               metric = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn);
+                               metric = mkf_u32(FO_CONFIG|FN_LIMIT, l->bind_conf->maxconn);
                                break;
                        case ST_F_STOT:
                                metric = mkf_u64(FN_COUNTER, l->counters->cum_conn);