MINOR: lb/api: let callers of take_conn/drop_conn tell if they have the lock
The two algos defining these functions (first and leastconn) do not need the
server's lock. However it's already present in pendconn_process_next_strm()
so the API must be updated so that the functions may take it if needed and
that the callers indicate whether they already own it.
As such, the call places (backend.c and stream.c) now do not take it
anymore, queue.c was unchanged since it's already held, and both "first"
and "leastconn" were updated to take it if not already held.
A quick test on the "first" algo showed a jump from 432 to 565k rps by
just dropping the lock in stream.c!
(cherry picked from commit 59b0fecfd9f2fe96f6a9c2d1d4fbe34f71adb6e3)
Signed-off-by: Willy Tarreau <w@1wt.eu>
diff --git a/src/stream.c b/src/stream.c
index 7b58e2a..7e33d82 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -2505,11 +2505,8 @@
_HA_ATOMIC_SUB(&oldsrv->served, 1);
_HA_ATOMIC_SUB(&oldsrv->proxy->served, 1);
__ha_barrier_atomic_store();
- if (oldsrv->proxy->lbprm.server_drop_conn) {
- HA_SPIN_LOCK(SERVER_LOCK, &oldsrv->lock);
- oldsrv->proxy->lbprm.server_drop_conn(oldsrv);
- HA_SPIN_UNLOCK(SERVER_LOCK, &oldsrv->lock);
- }
+ if (oldsrv->proxy->lbprm.server_drop_conn)
+ oldsrv->proxy->lbprm.server_drop_conn(oldsrv, 0);
stream_del_srv_conn(sess);
}
@@ -2517,11 +2514,8 @@
_HA_ATOMIC_ADD(&newsrv->served, 1);
_HA_ATOMIC_ADD(&newsrv->proxy->served, 1);
__ha_barrier_atomic_store();
- if (newsrv->proxy->lbprm.server_take_conn) {
- HA_SPIN_LOCK(SERVER_LOCK, &newsrv->lock);
- newsrv->proxy->lbprm.server_take_conn(newsrv);
- HA_SPIN_UNLOCK(SERVER_LOCK, &newsrv->lock);
- }
+ if (newsrv->proxy->lbprm.server_take_conn)
+ newsrv->proxy->lbprm.server_take_conn(newsrv, 0);
stream_add_srv_conn(sess, newsrv);
}
}