balance: round-robin-Turn für parallele Anfragen atomar
Zwei gleichzeitig startende Anfragen lasen denselben rr_turn und wählten dasselbe Ziel; die zweite wartete dann am Model-Gate des ersten, statt auf die nächste Box zu gehen. Der Turn wird jetzt unter einem Mutex gezogen.
This commit is contained in:
1 parent
df61582139
commit
e302d1bc01
1 file changed
+8
-1
+8
-1
@@ -2087,6 +2087,8 @@ static double ep_score(const j_endpoint *ep)
|
||||
|
||||
/* Order the rule's targets according to the configured balance mode. "first"
|
||||
* keeps rule order, which is what a failover chain wants; the others sort. */
|
||||
static pthread_mutex_t g_rr_mu = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static void balance_order(const j_rule *r, int *order, int n)
|
||||
{
|
||||
static unsigned long rr_turn;
|
||||
@@ -2111,7 +2113,12 @@ static void balance_order(const j_rule *r, int *order, int n)
|
||||
slots[ns++] = i;
|
||||
}
|
||||
if (!ns) return;
|
||||
int shift = (int)(rr_turn++ % (unsigned long)ns);
|
||||
/* Concurrent requests must get different turns; otherwise two requests
|
||||
* starting together both pick the same first target and queue there. */
|
||||
pthread_mutex_lock(&g_rr_mu);
|
||||
unsigned long turn = rr_turn++;
|
||||
pthread_mutex_unlock(&g_rr_mu);
|
||||
int shift = (int)(turn % (unsigned long)ns);
|
||||
int seen = 0;
|
||||
for (int s2 = 0; s2 < ns && seen < n; s2++) {
|
||||
int t = slots[(s2 + shift) % ns];
|
||||
|
||||
Reference in new issue
Block a user