wait command optimization (#7333)
Client that issued WAIT last will most likely have the highest replication offset, so imagine a probably common case where all clients are waiting for the same number of replicas. we prefer the loop to start from the last client (one waiting for the highest offset), so that the optimization in the function will call replicationCountAcksByOffset for each client until it found a good one, and stop calling it for the rest of the clients. the way the loop was implemented would mean that in such case it is likely to call replicationCountAcksByOffset for all clients. Note: the change from > to >= is not directly related to the above. Co-authored-by: 曹正斌 <caozb@jiedaibao.com>
This commit is contained in:
parent
47637bea6d
commit
d10b2f3173
@ -3068,7 +3068,7 @@ void waitCommand(client *c) {
|
|||||||
c->bpop.timeout = timeout;
|
c->bpop.timeout = timeout;
|
||||||
c->bpop.reploffset = offset;
|
c->bpop.reploffset = offset;
|
||||||
c->bpop.numreplicas = numreplicas;
|
c->bpop.numreplicas = numreplicas;
|
||||||
listAddNodeTail(server.clients_waiting_acks,c);
|
listAddNodeHead(server.clients_waiting_acks,c);
|
||||||
blockClient(c,BLOCKED_WAIT);
|
blockClient(c,BLOCKED_WAIT);
|
||||||
|
|
||||||
/* Make sure that the server will send an ACK request to all the slaves
|
/* Make sure that the server will send an ACK request to all the slaves
|
||||||
@ -3103,8 +3103,8 @@ void processClientsWaitingReplicas(void) {
|
|||||||
* offset and number of replicas, we remember it so the next client
|
* offset and number of replicas, we remember it so the next client
|
||||||
* may be unblocked without calling replicationCountAcksByOffset()
|
* may be unblocked without calling replicationCountAcksByOffset()
|
||||||
* if the requested offset / replicas were equal or less. */
|
* if the requested offset / replicas were equal or less. */
|
||||||
if (last_offset && last_offset > c->bpop.reploffset &&
|
if (last_offset && last_offset >= c->bpop.reploffset &&
|
||||||
last_numreplicas > c->bpop.numreplicas)
|
last_numreplicas >= c->bpop.numreplicas)
|
||||||
{
|
{
|
||||||
unblockClient(c);
|
unblockClient(c);
|
||||||
addReplyLongLong(c,last_numreplicas);
|
addReplyLongLong(c,last_numreplicas);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user