summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcaozb <1162650653@qq.com>2020-08-13 19:30:51 +0800
committerGitHub <noreply@github.com>2020-08-13 14:30:51 +0300
commitd10b2f3173ebfcc673d4ec36efef512802e3a535 (patch)
tree1298438f9a8a2d49e30076f30e3ad70cdd67bb6c
parent47637bea6d12d899f69a6b384ee7b024177006de (diff)
downloadredis-d10b2f3173ebfcc673d4ec36efef512802e3a535.tar.gz
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>
-rw-r--r--src/replication.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/replication.c b/src/replication.c
index 846f3a26b..1e1be345c 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -3068,7 +3068,7 @@ void waitCommand(client *c) {
c->bpop.timeout = timeout;
c->bpop.reploffset = offset;
c->bpop.numreplicas = numreplicas;
- listAddNodeTail(server.clients_waiting_acks,c);
+ listAddNodeHead(server.clients_waiting_acks,c);
blockClient(c,BLOCKED_WAIT);
/* 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
* may be unblocked without calling replicationCountAcksByOffset()
* if the requested offset / replicas were equal or less. */
- if (last_offset && last_offset > c->bpop.reploffset &&
- last_numreplicas > c->bpop.numreplicas)
+ if (last_offset && last_offset >= c->bpop.reploffset &&
+ last_numreplicas >= c->bpop.numreplicas)
{
unblockClient(c);
addReplyLongLong(c,last_numreplicas);