remove liveServers and simply return inner len

This commit is contained in:
keatonLiu 2023-12-11 23:45:33 +08:00
parent 6d179bbec8
commit 1658efb256
1 changed files with 4 additions and 4 deletions

View File

@ -13,7 +13,6 @@ import (
"sort"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/VividCortex/ewma"
@ -228,15 +227,16 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
registeredServers := make([]RegisteredServer, len(serversInfo.registeredServers))
copy(registeredServers, serversInfo.registeredServers)
serversInfo.RUnlock()
var liveServers atomic.Int32
// Always have proxy.certRefreshConcurrency servers being refreshed in parallel
countChannel := make(chan struct{}, proxy.certRefreshConcurrency)
waitChannel := make(chan struct{})
var err error
for i := range registeredServers {
// Would block if countChannel is already filled
countChannel <- struct{}{}
go func(registeredServer *RegisteredServer) {
if err = serversInfo.refreshServer(proxy, registeredServer.name, registeredServer.stamp); err == nil {
liveServers.Add(1)
proxy.xTransport.internalResolverReady = true
}
<-countChannel
@ -262,7 +262,7 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
dlog.Noticef("Server with the lowest initial latency: %s (rtt: %dms)", inner[0].Name, inner[0].initialRtt)
}
serversInfo.Unlock()
return int(liveServers.Load()), err
return innerLen, err
}
func (serversInfo *ServersInfo) estimatorUpdate(currentActive int) {