From 52b1db94554d48ea0e09fdac30b2d5542710d763 Mon Sep 17 00:00:00 2001 From: Joris Minjat Date: Thu, 15 Dec 2016 16:40:45 +0000 Subject: [PATCH] Pinging all nodes in same time (Otherwise if cluster is 100 nodes it can be quite slow) --- cluster.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cluster.go b/cluster.go index 9baad73..4313fb1 100644 --- a/cluster.go +++ b/cluster.go @@ -435,15 +435,21 @@ func (c *ClusterClient) reloadSlots() { func (c *ClusterClient) setNodesLatency() { const n = 10 + wg := &sync.WaitGroup{} for _, node := range c.getNodes() { - var latency time.Duration - for i := 0; i < n; i++ { - t1 := time.Now() - node.Client.Ping() - latency += time.Since(t1) - } - node.Latency = latency / n + wg.Add(1) + go func(node *clusterNode) { + defer wg.Done() + var latency time.Duration + for i := 0; i < n; i++ { + t1 := time.Now() + node.Client.Ping() + latency += time.Since(t1) + } + node.Latency = latency / n + }(node) } + wg.Wait() } // reaper closes idle connections to the cluster.