@@ -251,14 +251,14 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
251251 return liveServers , err
252252}
253253
254- func (serversInfo * ServersInfo ) estimatorUpdate () {
254+ func (serversInfo * ServersInfo ) estimatorUpdate (currentActive int ) {
255255 // serversInfo.RWMutex is assumed to be Locked
256256 serversCount := len (serversInfo .inner )
257257 activeCount := serversInfo .lbStrategy .getActiveCount (serversCount )
258258 if activeCount == serversCount {
259259 return
260260 }
261- candidate , currentActive := rand .Intn (serversCount - activeCount )+ activeCount , rand . Intn ( activeCount )
261+ candidate := rand .Intn (serversCount - activeCount )+ activeCount
262262 candidateRtt , currentActiveRtt := serversInfo .inner [candidate ].rtt .Value (), serversInfo .inner [currentActive ].rtt .Value ()
263263 if currentActiveRtt < 0 {
264264 currentActiveRtt = candidateRtt
@@ -297,10 +297,10 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
297297 serversInfo .Unlock ()
298298 return nil
299299 }
300+ candidate := serversInfo .lbStrategy .getCandidate (serversCount )
300301 if serversInfo .lbEstimator {
301- serversInfo .estimatorUpdate ()
302+ serversInfo .estimatorUpdate (candidate )
302303 }
303- candidate := serversInfo .lbStrategy .getCandidate (serversCount )
304304 serverInfo := serversInfo .inner [candidate ]
305305 dlog .Debugf ("Using candidate [%s] RTT: %d" , (* serverInfo ).Name , int ((* serverInfo ).rtt .Value ()))
306306 serversInfo .Unlock ()
0 commit comments