]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lb/first: use a read lock in fas_get_next_server()
authorWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2020 17:45:42 +0000 (19:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2020 17:49:49 +0000 (19:49 +0200)
The "first" algorithm creates a lot of contention because all threads
focus on the same server by definition (the first available one). By
turning the exclusive lock to a read lock in fas_get_next_server(),
the request rate increases by 16% for 8 threads when many servers are
getting close to their maxconn.

src/lb_fas.c

index 43ff6a582259f5e802b50dd2160b68d13afc16af..e30606507c14bc4bc068738d5991094373d3102c 100644 (file)
@@ -300,7 +300,7 @@ struct server *fas_get_next_server(struct proxy *p, struct server *srvtoavoid)
 
        srv = avoided = NULL;
 
-       HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
+       HA_RWLOCK_RDLOCK(LBPRM_LOCK, &p->lbprm.lock);
        if (p->srv_act)
                node = eb32_first(&p->lbprm.fas.act);
        else if (p->lbprm.fbck) {
@@ -336,7 +336,7 @@ struct server *fas_get_next_server(struct proxy *p, struct server *srvtoavoid)
        if (!srv)
                srv = avoided;
   out:
-       HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+       HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
        return srv;
 }