mirror of https://github.com/go-redis/redis.git
Pinging all nodes in same time (Otherwise if cluster is 100 nodes it can be quite slow)
This commit is contained in:
parent
8a8d997ad5
commit
52b1db9455
20
cluster.go
20
cluster.go
|
@ -435,15 +435,21 @@ func (c *ClusterClient) reloadSlots() {
|
||||||
|
|
||||||
func (c *ClusterClient) setNodesLatency() {
|
func (c *ClusterClient) setNodesLatency() {
|
||||||
const n = 10
|
const n = 10
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
for _, node := range c.getNodes() {
|
for _, node := range c.getNodes() {
|
||||||
var latency time.Duration
|
wg.Add(1)
|
||||||
for i := 0; i < n; i++ {
|
go func(node *clusterNode) {
|
||||||
t1 := time.Now()
|
defer wg.Done()
|
||||||
node.Client.Ping()
|
var latency time.Duration
|
||||||
latency += time.Since(t1)
|
for i := 0; i < n; i++ {
|
||||||
}
|
t1 := time.Now()
|
||||||
node.Latency = latency / n
|
node.Client.Ping()
|
||||||
|
latency += time.Since(t1)
|
||||||
|
}
|
||||||
|
node.Latency = latency / n
|
||||||
|
}(node)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// reaper closes idle connections to the cluster.
|
// reaper closes idle connections to the cluster.
|
||||||
|
|
Loading…
Reference in New Issue