@@ -251,14 +251,14 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
251
251
return liveServers , err
252
252
}
253
253
254
- func (serversInfo * ServersInfo ) estimatorUpdate () {
254
+ func (serversInfo * ServersInfo ) estimatorUpdate (currentActive int ) {
255
255
// serversInfo.RWMutex is assumed to be Locked
256
256
serversCount := len (serversInfo .inner )
257
257
activeCount := serversInfo .lbStrategy .getActiveCount (serversCount )
258
258
if activeCount == serversCount {
259
259
return
260
260
}
261
- candidate , currentActive := rand .Intn (serversCount - activeCount )+ activeCount , rand . Intn ( activeCount )
261
+ candidate := rand .Intn (serversCount - activeCount )+ activeCount
262
262
candidateRtt , currentActiveRtt := serversInfo .inner [candidate ].rtt .Value (), serversInfo .inner [currentActive ].rtt .Value ()
263
263
if currentActiveRtt < 0 {
264
264
currentActiveRtt = candidateRtt
@@ -297,10 +297,10 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
297
297
serversInfo .Unlock ()
298
298
return nil
299
299
}
300
+ candidate := serversInfo .lbStrategy .getCandidate (serversCount )
300
301
if serversInfo .lbEstimator {
301
- serversInfo .estimatorUpdate ()
302
+ serversInfo .estimatorUpdate (candidate )
302
303
}
303
- candidate := serversInfo .lbStrategy .getCandidate (serversCount )
304
304
serverInfo := serversInfo .inner [candidate ]
305
305
dlog .Debugf ("Using candidate [%s] RTT: %d" , (* serverInfo ).Name , int ((* serverInfo ).rtt .Value ()))
306
306
serversInfo .Unlock ()
0 commit comments