summaryrefslogtreecommitdiff
path: root/src/cluster.c
diff options
context:
space:
mode:
authorjudeng <abc3844@126.com>2022-06-21 12:02:22 +0800
committerGitHub <noreply@github.com>2022-06-20 21:02:22 -0700
commitff6419658bd8c8800734a7f19520c2aa7cd68a90 (patch)
tree648cf9c6132e461417411b35bbc6c69faec2ff5f /src/cluster.c
parent99a425d0f3b7b00896cb855d5de4ae93be1fe3f0 (diff)
downloadredis-ff6419658bd8c8800734a7f19520c2aa7cd68a90.tar.gz
Optimize the performance of clusterSendPing for large clusters (#10624)
Optimize the performance of clusterSendPing by improving speed of checking for duplicate items in gossip.
Diffstat (limited to 'src/cluster.c')
-rw-r--r--src/cluster.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/cluster.c b/src/cluster.c
index 0975db53a..cdbc565ec 100644
--- a/src/cluster.c
+++ b/src/cluster.c
@@ -964,6 +964,7 @@ clusterNode *createClusterNode(char *nodename, int flags) {
node->numslaves = 0;
node->slaves = NULL;
node->slaveof = NULL;
+ node->last_in_ping_gossip = 0;
node->ping_sent = node->pong_received = 0;
node->data_received = 0;
node->fail_time = 0;
@@ -2847,18 +2848,6 @@ void clusterBuildMessageHdr(clusterMsg *hdr, int type) {
* totlen field is up to the caller. */
}
-/* Return non zero if the node is already present in the gossip section of the
- * message pointed by 'hdr' and having 'count' gossip entries. Otherwise
- * zero is returned. Helper for clusterSendPing(). */
-int clusterNodeIsInGossipSection(clusterMsg *hdr, int count, clusterNode *n) {
- int j;
- for (j = 0; j < count; j++) {
- if (memcmp(hdr->data.ping.gossip[j].nodename,n->name,
- CLUSTER_NAMELEN) == 0) break;
- }
- return j != count;
-}
-
/* Set the i-th entry of the gossip section in the message pointed by 'hdr'
* to the info of the specified node 'n'. */
void clusterSetGossipEntry(clusterMsg *hdr, int i, clusterNode *n) {
@@ -2878,6 +2867,8 @@ void clusterSetGossipEntry(clusterMsg *hdr, int i, clusterNode *n) {
/* Send a PING or PONG packet to the specified node, making sure to add enough
* gossip information. */
void clusterSendPing(clusterLink *link, int type) {
+ static unsigned long long cluster_pings_sent = 0;
+ cluster_pings_sent++;
unsigned char *buf;
clusterMsg *hdr;
int gossipcount = 0; /* Number of gossip sections added so far. */
@@ -2967,10 +2958,11 @@ void clusterSendPing(clusterLink *link, int type) {
}
/* Do not add a node we already have. */
- if (clusterNodeIsInGossipSection(hdr,gossipcount,this)) continue;
+ if (this->last_in_ping_gossip == cluster_pings_sent) continue;
/* Add it */
clusterSetGossipEntry(hdr,gossipcount,this);
+ this->last_in_ping_gossip = cluster_pings_sent;
freshnodes--;
gossipcount++;
}
@@ -2987,7 +2979,6 @@ void clusterSendPing(clusterLink *link, int type) {
if (node->flags & CLUSTER_NODE_NOADDR) continue;
if (!(node->flags & CLUSTER_NODE_PFAIL)) continue;
clusterSetGossipEntry(hdr,gossipcount,node);
- freshnodes--;
gossipcount++;
/* We take the count of the slots we allocated, since the
* PFAIL stats may not match perfectly with the current number