mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MEDIUM: queue: refine the locking in process_srv_queue()
The lock in process_srv_queue() was placed around the whole loop to avoid the cost of taking/releasing it multiple times. But in practice almost all calls to this function only dequeue a single connection, so that argument doesn't really stand. However by placing the lock inside the loop, we'd make it possible to release it before manipulating the pendconn and waking the task up. That's what this patch does. This increases the performance from 431k to 491k req/s on 16 threads with 20 servers under leastconn. The performance profile changes from this: 14.09% haproxy [.] process_srv_queue 10.22% haproxy [.] fwlc_srv_reposition 6.39% haproxy [.] fwlc_get_next_server 3.97% haproxy [.] pendconn_dequeue 3.84% haproxy [.] pendconn_add to this: 13.03% haproxy [.] fwlc_srv_reposition 8.08% haproxy [.] fwlc_get_next_server 3.62% haproxy [.] process_srv_queue 1.78% haproxy [.] pendconn_dequeue 1.74% haproxy [.] pendconn_add The difference is even slightly more visible in roundrobin which does not have take_conn() call.
This commit is contained in:
parent
3e92a31783
commit
1b648c857b
16
src/queue.c
16
src/queue.c
@ -340,27 +340,29 @@ void process_srv_queue(struct server *s, int server_locked)
|
|||||||
int done = 0;
|
int done = 0;
|
||||||
int maxconn;
|
int maxconn;
|
||||||
|
|
||||||
if (!server_locked)
|
|
||||||
HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
|
|
||||||
HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
|
||||||
maxconn = srv_dynamic_maxconn(s);
|
maxconn = srv_dynamic_maxconn(s);
|
||||||
while (s->served < maxconn) {
|
while (s->served < maxconn) {
|
||||||
struct pendconn *pc;
|
struct pendconn *pc;
|
||||||
|
|
||||||
|
if (!server_locked)
|
||||||
|
HA_SPIN_LOCK(SERVER_LOCK, &s->lock);
|
||||||
|
HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
|
||||||
|
|
||||||
pc = pendconn_process_next_strm(s, p);
|
pc = pendconn_process_next_strm(s, p);
|
||||||
|
|
||||||
|
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);
|
||||||
|
if (!server_locked)
|
||||||
|
HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
|
||||||
|
|
||||||
if (!pc)
|
if (!pc)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
done++;
|
done++;
|
||||||
|
|
||||||
_HA_ATOMIC_INC(&s->served);
|
_HA_ATOMIC_INC(&s->served);
|
||||||
|
|
||||||
stream_add_srv_conn(pc->strm, s);
|
stream_add_srv_conn(pc->strm, s);
|
||||||
task_wakeup(pc->strm->task, TASK_WOKEN_RES);
|
task_wakeup(pc->strm->task, TASK_WOKEN_RES);
|
||||||
}
|
}
|
||||||
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);
|
|
||||||
if (!server_locked)
|
|
||||||
HA_SPIN_UNLOCK(SERVER_LOCK, &s->lock);
|
|
||||||
|
|
||||||
_HA_ATOMIC_ADD(&p->served, done);
|
_HA_ATOMIC_ADD(&p->served, done);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user