The per-thread applet counters of a peers section are used to pick the
least loaded thread when creating an outgoing peer session. They are
incremented in peer_session_create() for outgoing sessions only, but
decremented in __peer_session_deinit() for all sessions, including
incoming ones. Each incoming session thus makes the counter of its thread
drift towards negative values, and outgoing sessions then tend to be
created on the threads which handled incoming ones, defeating the load
balancing.
Must be backported as far as 3.0.
curpeer->flags |= PEER_F_ALIVE;
appctx->svcctx = curpeer;
appctx->st0 = PEER_SESS_ST_SENDSUCCESS;
+ /* peer_session_create() accounts outgoing sessions,
+ * while __peer_session_deinit() releases the counter
+ * for every session, so account this incoming one too.
+ */
+ HA_ATOMIC_INC(&curpeer->peers->applet_count[tid]);
_HA_ATOMIC_INC(&active_peers);
}
__fallthrough;