>From 3fc983b719bd4d8af80037c36e7032e0af383557 Mon Sep 17 00:00:00 2001
From: Anthony Deschamps <[email protected]>
Date: Tue, 13 Feb 2024 18:11:56 -0500
Subject: [PATCH] MINOR: lb-chash: Respect maxconn when selecting a server
This is useful in a situation where hash-balance-factor isn't quite
optimal. For example:
If we have two servers at times of low traffic, if server A has one active
request and server B has
zero, we might prefer that a second request for the same resource also be
routed to server A; with
hash-balance-factor set to anything less than 200, that request would
routed to server B, causing it
to dedicate resources to a resource that is already loaded/warm in server
A. Meanwhile, at times of
high traffic, we still want multiple servers to be able to share the load
of highly used resources.
---
src/lb_chash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lb_chash.c b/src/lb_chash.c
index 4e8fb1536..1c8034d89 100644
--- a/src/lb_chash.c
+++ b/src/lb_chash.c
@@ -371,7 +371,7 @@ struct server *chash_get_server_hash(struct proxy *p,
unsigned int hash, const s
}
loop = 0;
- while (nsrv == avoid || (p->lbprm.hash_balance_factor &&
!chash_server_is_eligible(nsrv))) {
+ while (nsrv == avoid || (nsrv->maxconn && nsrv->served >= nsrv->maxconn)
|| (p->lbprm.hash_balance_factor && !chash_server_is_eligible(nsrv))) {
next = eb32_next(next);
if (!next) {
next = eb32_first(root);
--
2.43.0