diff options
author | Wang Yuan <wangyuan21@baidu.com> | 2022-04-17 14:41:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-17 09:41:46 +0300 |
commit | a9d5cfa99bf2d9a88daad7add5afb9ff9287a0c5 (patch) | |
tree | 76dcf766893100e2fce7c789fd82b39bec4fc916 /src | |
parent | fe1c096b1849b633f41f69f432c4236428035950 (diff) | |
download | redis-a9d5cfa99bf2d9a88daad7add5afb9ff9287a0c5.tar.gz |
Optimize the call of prepareReplicasToWrite (#10588)
From #9166, we call several times of prepareReplicasToWrite when propagating
one write command to replication stream (once per argument, same as we do for
normal clients), that is not necessary. Now we only call it one time per command
at the begin of feeding replication stream.
This results in reducing CPU consumption and slightly better performance,
specifically when there are many replicas.
Diffstat (limited to 'src')
-rw-r--r-- | src/replication.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/replication.c b/src/replication.c index d183b7d4a..e3ee728da 100644 --- a/src/replication.c +++ b/src/replication.c @@ -327,9 +327,6 @@ void feedReplicationBuffer(char *s, size_t len) { server.master_repl_offset += len; server.repl_backlog->histlen += len; - /* Install write handler for all replicas. */ - prepareReplicasToWrite(); - size_t start_pos = 0; /* The position of referenced block to start sending. */ listNode *start_node = NULL; /* Replica/backlog starts referenced node. */ int add_new_block = 0; /* Create new block if current block is total used. */ @@ -440,6 +437,10 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) { /* We can't have slaves attached and no backlog. */ serverAssert(!(listLength(slaves) != 0 && server.repl_backlog == NULL)); + /* Must install write handler for all replicas first before feeding + * replication stream. */ + prepareReplicasToWrite(); + /* Send SELECT command to every slave if needed. */ if (server.slaveseldb != dictid) { robj *selectcmd; @@ -539,7 +540,12 @@ void replicationFeedStreamFromMasterStream(char *buf, size_t buflen) { /* There must be replication backlog if having attached slaves. */ if (listLength(server.slaves)) serverAssert(server.repl_backlog != NULL); - if (server.repl_backlog) feedReplicationBuffer(buf,buflen); + if (server.repl_backlog) { + /* Must install write handler for all replicas first before feeding + * replication stream. */ + prepareReplicasToWrite(); + feedReplicationBuffer(buf,buflen); + } } void replicationFeedMonitors(client *c, list *monitors, int dictid, robj **argv, int argc) { |