MINOR: peers: Track number of applets run by thread

Maintain number of peers applets run on all threads. It will be used
in next patch for least loaded thread selection.
This commit is contained in:
Maciej Zdeb 2022-05-16 17:26:20 +02:00 committed by Christopher Faulet
parent d9c1d33fa1
commit d01be2ab13
2 changed files with 8 additions and 0 deletions

View File

@ -102,6 +102,7 @@ struct peers {
unsigned int resync_timeout; /* resync timeout timer */ unsigned int resync_timeout; /* resync timeout timer */
int count; /* total of peers */ int count; /* total of peers */
int disabled; /* peers proxy disabled if >0 */ int disabled; /* peers proxy disabled if >0 */
int applet_count[MAX_THREADS]; /* applet count per thread */
}; };
/* LRU cache for dictionaies */ /* LRU cache for dictionaies */

View 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) void __peer_session_deinit(struct peer *peer)
{ {
struct peers *peers = peer->peers; struct peers *peers = peer->peers;
int thr;
if (!peers || !peer->appctx) if (!peers || !peer->appctx)
return; 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) if (peer->appctx->st0 == PEER_SESS_ST_WAITMSG)
HA_ATOMIC_DEC(&connected_peers); 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) static struct appctx *peer_session_create(struct peers *peers, struct peer *peer)
{ {
struct appctx *appctx; struct appctx *appctx;
unsigned int thr = tid;
peer->new_conn++; peer->new_conn++;
peer->reconnect = tick_add(now_ms, MS_TO_TICKS(PEER_RECONNECT_TIMEOUT)); 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) if (appctx_init(appctx) == -1)
goto out_free_appctx; goto out_free_appctx;
HA_ATOMIC_INC(&peers->applet_count[thr]);
return appctx; return appctx;
/* Error unrolling */ /* Error unrolling */
@ -3492,6 +3498,7 @@ int peers_init_sync(struct peers *peers)
if (!peers->sync_task) if (!peers->sync_task)
return 0; return 0;
memset(peers->applet_count, 0, sizeof(peers->applet_count));
peers->sync_task->process = process_peer_sync; peers->sync_task->process = process_peer_sync;
peers->sync_task->context = (void *)peers; peers->sync_task->context = (void *)peers;
peers->sighandler = signal_register_task(0, peers->sync_task, 0); peers->sighandler = signal_register_task(0, peers->sync_task, 0);