]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: peers: Track number of applets run by thread
authorMaciej Zdeb <maciej@zdeb.pl>
Mon, 16 May 2022 15:26:20 +0000 (17:26 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 May 2022 14:13:22 +0000 (16:13 +0200)
Maintain number of peers applets run on all threads. It will be used
in next patch for least loaded thread selection.

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

index 6a2e749258f85ced969bde468cb2b7f3c13f1dd2..6a1c215004041c3560be8f3c2cbe735ba163e2d7 100644 (file)
@@ -102,6 +102,7 @@ struct peers {
        unsigned int resync_timeout;    /* resync timeout timer */
        int count;                      /* total of peers */
        int disabled;                   /* peers proxy disabled if >0 */
+       int applet_count[MAX_THREADS];  /* applet count per thread */
 };
 
 /* LRU cache for dictionaies */
index 0e48004770038de5b78e55c7e543f964a9e06710..d46afcfba24ef799022ce1208d4217f4306c0f60 100644 (file)
@@ -1035,10 +1035,14 @@ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params *
 void __peer_session_deinit(struct peer *peer)
 {
        struct peers *peers = peer->peers;
+       int thr;
 
        if (!peers || !peer->appctx)
                return;
 
+       thr = my_ffsl(peer->appctx->t->thread_mask) - 1;
+       HA_ATOMIC_DEC(&peers->applet_count[thr]);
+
        if (peer->appctx->st0 == PEER_SESS_ST_WAITMSG)
                HA_ATOMIC_DEC(&connected_peers);
 
@@ -3192,6 +3196,7 @@ void peers_setup_frontend(struct proxy *fe)
 static struct appctx *peer_session_create(struct peers *peers, struct peer *peer)
 {
        struct appctx *appctx;
+       unsigned int thr = tid;
 
        peer->new_conn++;
        peer->reconnect = tick_add(now_ms, MS_TO_TICKS(PEER_RECONNECT_TIMEOUT));
@@ -3210,6 +3215,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
        if (appctx_init(appctx) == -1)
                goto out_free_appctx;
 
+       HA_ATOMIC_INC(&peers->applet_count[thr]);
        return appctx;
 
        /* Error unrolling */
@@ -3492,6 +3498,7 @@ int peers_init_sync(struct peers *peers)
        if (!peers->sync_task)
                return 0;
 
+       memset(peers->applet_count, 0, sizeof(peers->applet_count));
        peers->sync_task->process = process_peer_sync;
        peers->sync_task->context = (void *)peers;
        peers->sighandler = signal_register_task(0, peers->sync_task, 0);