Pinging all nodes in same time (Otherwise if cluster is 100 nodes it can be quite slow)

This commit is contained in:
Joris Minjat 2016-12-15 16:40:45 +00:00
parent 8a8d997ad5
commit 52b1db9455
1 changed files with 13 additions and 7 deletions

View File

@ -435,7 +435,11 @@ func (c *ClusterClient) reloadSlots() {
func (c *ClusterClient) setNodesLatency() {
const n = 10
wg := &sync.WaitGroup{}
for _, node := range c.getNodes() {
wg.Add(1)
go func(node *clusterNode) {
defer wg.Done()
var latency time.Duration
for i := 0; i < n; i++ {
t1 := time.Now()
@ -443,7 +447,9 @@ func (c *ClusterClient) setNodesLatency() {
latency += time.Since(t1)
}
node.Latency = latency / n
}(node)
}
wg.Wait()
}
// reaper closes idle connections to the cluster.