Revert "Implement pN load balancing strategy (#1188)"
This reverts commit 014a75c0ec
.
This commit is contained in:
parent
014a75c0ec
commit
4c402a6012
|
@ -363,22 +363,17 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
|
||||||
switch strings.ToLower(config.LBStrategy) {
|
switch strings.ToLower(config.LBStrategy) {
|
||||||
case "":
|
case "":
|
||||||
// default
|
// default
|
||||||
|
case "p2":
|
||||||
|
lbStrategy = LBStrategyP2
|
||||||
case "ph":
|
case "ph":
|
||||||
lbStrategy = LBStrategyPH
|
lbStrategy = LBStrategyPH
|
||||||
case "fastest":
|
case "fastest":
|
||||||
case "first":
|
case "first":
|
||||||
lbStrategy = LBStrategy(1)
|
lbStrategy = LBStrategyFirst
|
||||||
case "random":
|
case "random":
|
||||||
lbStrategy = LBStrategyRandom
|
lbStrategy = LBStrategyRandom
|
||||||
|
|
||||||
default:
|
default:
|
||||||
n, err := strconv.ParseUint(strings.TrimPrefix(config.LBStrategy, "p"), 10, 64)
|
dlog.Warnf("Unknown load balancing strategy: [%s]", config.LBStrategy)
|
||||||
|
|
||||||
if err == nil && n >= 1 {
|
|
||||||
lbStrategy = LBStrategy(n)
|
|
||||||
} else {
|
|
||||||
dlog.Warnf("Unknown load balancing strategy: [%s]", config.LBStrategy)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
proxy.serversInfo.lbStrategy = lbStrategy
|
proxy.serversInfo.lbStrategy = lbStrategy
|
||||||
proxy.serversInfo.lbEstimator = config.LBEstimator
|
proxy.serversInfo.lbEstimator = config.LBEstimator
|
||||||
|
|
|
@ -126,7 +126,6 @@ keepalive = 30
|
||||||
|
|
||||||
|
|
||||||
## Load-balancing strategy: 'p2' (default), 'ph', 'first' or 'random'
|
## Load-balancing strategy: 'p2' (default), 'ph', 'first' or 'random'
|
||||||
## Use pN where N is a positive number to choose between N first fastest servers.
|
|
||||||
|
|
||||||
# lb_strategy = 'p2'
|
# lb_strategy = 'p2'
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,14 @@ type ServerInfo struct {
|
||||||
type LBStrategy int
|
type LBStrategy int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LBStrategyRandom = LBStrategy(0)
|
LBStrategyNone = LBStrategy(iota)
|
||||||
LBStrategyPH = LBStrategy(-1)
|
LBStrategyP2
|
||||||
|
LBStrategyPH
|
||||||
|
LBStrategyFirst
|
||||||
|
LBStrategyRandom
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultLBStrategy = LBStrategy(2)
|
const DefaultLBStrategy = LBStrategyP2
|
||||||
|
|
||||||
type ServersInfo struct {
|
type ServersInfo struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
@ -208,12 +211,14 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
|
||||||
}
|
}
|
||||||
var candidate int
|
var candidate int
|
||||||
switch serversInfo.lbStrategy {
|
switch serversInfo.lbStrategy {
|
||||||
case -1: // First half
|
case LBStrategyFirst:
|
||||||
|
candidate = 0
|
||||||
|
case LBStrategyPH:
|
||||||
candidate = rand.Intn(Max(Min(serversCount, 2), serversCount/2))
|
candidate = rand.Intn(Max(Min(serversCount, 2), serversCount/2))
|
||||||
case 0: // Random
|
case LBStrategyRandom:
|
||||||
candidate = rand.Intn(serversCount)
|
candidate = rand.Intn(serversCount)
|
||||||
default: // First N
|
default:
|
||||||
candidate = rand.Intn(int(serversInfo.lbStrategy)) % serversCount
|
candidate = rand.Intn(Min(serversCount, 2))
|
||||||
}
|
}
|
||||||
serverInfo := serversInfo.inner[candidate]
|
serverInfo := serversInfo.inner[candidate]
|
||||||
dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value()))
|
dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value()))
|
||||||
|
|
Loading…
Reference in New Issue