forked from mirror/redis
Merge pull request #452 from minjatJ/fix-cluster-latency_v4
Setting node latency can take a while
This commit is contained in:
commit
c938162545
20
cluster.go
20
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.
|
||||
|
|
Loading…
Reference in New Issue