parent
80426967bf
commit
3910873bf2
|
@ -72,7 +72,7 @@ const DefaultLBStrategy = LBStrategyP2
|
||||||
|
|
||||||
type ServersInfo struct {
|
type ServersInfo struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
inner []ServerInfo
|
inner []*ServerInfo
|
||||||
registeredServers []RegisteredServer
|
registeredServers []RegisteredServer
|
||||||
lbStrategy LBStrategy
|
lbStrategy LBStrategy
|
||||||
}
|
}
|
||||||
|
@ -110,10 +110,10 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp S
|
||||||
}
|
}
|
||||||
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
newServer.rtt = ewma.NewMovingAverage(RTTEwmaDecay)
|
||||||
if previousIndex >= 0 {
|
if previousIndex >= 0 {
|
||||||
serversInfo.inner[previousIndex] = newServer
|
serversInfo.inner[previousIndex] = &newServer
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
serversInfo.inner = append(serversInfo.inner, newServer)
|
serversInfo.inner = append(serversInfo.inner, &newServer)
|
||||||
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
serversInfo.registeredServers = append(serversInfo.registeredServers, RegisteredServer{name: name, stamp: stamp})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
||||||
}
|
}
|
||||||
candidate := rand.Intn(serversCount)
|
candidate := rand.Intn(serversCount)
|
||||||
if candidate == 0 {
|
if candidate == 0 {
|
||||||
return &serversInfo.inner[candidate]
|
return serversInfo.inner[candidate]
|
||||||
}
|
}
|
||||||
candidateRtt, currentBestRtt := serversInfo.inner[candidate].rtt.Value(), serversInfo.inner[0].rtt.Value()
|
candidateRtt, currentBestRtt := serversInfo.inner[candidate].rtt.Value(), serversInfo.inner[0].rtt.Value()
|
||||||
if currentBestRtt < 0 {
|
if currentBestRtt < 0 {
|
||||||
|
@ -200,8 +200,8 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
||||||
default:
|
default:
|
||||||
candidate = rand.Intn(Min(serversCount, 2))
|
candidate = rand.Intn(Min(serversCount, 2))
|
||||||
}
|
}
|
||||||
serverInfo := &serversInfo.inner[candidate]
|
serverInfo := serversInfo.inner[candidate]
|
||||||
dlog.Debugf("Using candidate %v: [%v]", candidate, serverInfo.Name)
|
dlog.Debugf("Using candidate %v: [%v]", candidate, (*serverInfo).Name)
|
||||||
|
|
||||||
return serverInfo
|
return serverInfo
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue