]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: listener: only store conn counts for local threads
authorWilly Tarreau <w@1wt.eu>
Tue, 28 Feb 2023 09:25:57 +0000 (10:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 Feb 2023 09:28:47 +0000 (10:28 +0100)
The listeners have a thr_conn[] array indexed on the thread number that
is used during connection redispatching to know what threads are the least
loaded. Since we introduced thread groups, and based on the fact that a
listener may only belong to one group, there's no point storing counters
for all threads, we just need to store them for all threads in the group.

Doing so reduces the struct listener from 1500 to 632 bytes. This may be
backported to 2.7 to save a bit of resources.

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

index 58dce2fe5a4d9c6bdf7c7219c43cbe2141ce5e91..0f6adde3ad1e0295524d3aae0b293d5b82e093cd 100644 (file)
@@ -236,7 +236,7 @@ struct listener {
        struct mt_list wait_queue;      /* link element to make the listener wait for something (LI_LIMITED)  */
        char *name;                     /* listener's name */
 
-       unsigned int thr_conn[MAX_THREADS]; /* number of connections per thread */
+       unsigned int thr_conn[MAX_THREADS_PER_GROUP]; /* number of connections per thread for the group */
 
        struct list by_fe;              /* chaining in frontend's list of listeners */
        struct list by_bind;            /* chaining in bind_conf's list of listeners */
index 47cf42634f7077ab8e8581cf5fd3e48ab884630b..2e373a3614f10581a86982118369f252d9a1385d 100644 (file)
@@ -141,7 +141,7 @@ struct task *accept_queue_process(struct task *t, void *context, unsigned int st
                        break;
 
                li = __objt_listener(conn->target);
-               _HA_ATOMIC_INC(&li->thr_conn[tid]);
+               _HA_ATOMIC_INC(&li->thr_conn[ti->ltid]);
                ret = li->bind_conf->accept(conn);
                if (ret <= 0) {
                        /* connection was terminated by the application */
@@ -1170,8 +1170,8 @@ void listener_accept(struct listener *l)
                                 *             than t2.
                                 */
 
-                               q1 += l->thr_conn[base + t1];
-                               q2 += l->thr_conn[base + t2];
+                               q1 += l->thr_conn[t1];
+                               q2 += l->thr_conn[t2];
 
                                if (q1 - q2 < 0) {
                                        t = t1;
@@ -1214,7 +1214,7 @@ void listener_accept(struct listener *l)
 #endif // USE_THREAD
 
  local_accept:
-               _HA_ATOMIC_INC(&l->thr_conn[tid]);
+               _HA_ATOMIC_INC(&l->thr_conn[ti->ltid]);
                ret = l->bind_conf->accept(cli_conn);
                if (unlikely(ret <= 0)) {
                        /* The connection was closed by stream_accept(). Either
@@ -1319,7 +1319,7 @@ void listener_release(struct listener *l)
        if (fe)
                _HA_ATOMIC_DEC(&fe->feconn);
        _HA_ATOMIC_DEC(&l->nbconn);
-       _HA_ATOMIC_DEC(&l->thr_conn[tid]);
+       _HA_ATOMIC_DEC(&l->thr_conn[ti->ltid]);
 
        if (l->state == LI_FULL || l->state == LI_LIMITED)
                relax_listener(l, 0, 0);