From 4c402a60121fff7730fe6eb9a31287e29471b292 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 20 Mar 2020 17:55:33 +0100 Subject: [PATCH] Revert "Implement pN load balancing strategy (#1188)" This reverts commit 014a75c0ec9fd4a6c84c030b88e2c12cf71d7d16. --- dnscrypt-proxy/config.go | 13 ++++--------- dnscrypt-proxy/example-dnscrypt-proxy.toml | 1 - dnscrypt-proxy/serversInfo.go | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index d0d91f3b..5c8abbea 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -363,22 +363,17 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error { switch strings.ToLower(config.LBStrategy) { case "": // default + case "p2": + lbStrategy = LBStrategyP2 case "ph": lbStrategy = LBStrategyPH case "fastest": case "first": - lbStrategy = LBStrategy(1) + lbStrategy = LBStrategyFirst case "random": lbStrategy = LBStrategyRandom - default: - n, err := strconv.ParseUint(strings.TrimPrefix(config.LBStrategy, "p"), 10, 64) - - if err == nil && n >= 1 { - lbStrategy = LBStrategy(n) - } else { - dlog.Warnf("Unknown load balancing strategy: [%s]", config.LBStrategy) - } + dlog.Warnf("Unknown load balancing strategy: [%s]", config.LBStrategy) } proxy.serversInfo.lbStrategy = lbStrategy proxy.serversInfo.lbEstimator = config.LBEstimator diff --git a/dnscrypt-proxy/example-dnscrypt-proxy.toml b/dnscrypt-proxy/example-dnscrypt-proxy.toml index 041deb76..b4ba6910 100644 --- a/dnscrypt-proxy/example-dnscrypt-proxy.toml +++ b/dnscrypt-proxy/example-dnscrypt-proxy.toml @@ -126,7 +126,6 @@ keepalive = 30 ## 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' diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index 4a79436a..6327f7c0 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -65,11 +65,14 @@ type ServerInfo struct { type LBStrategy int const ( - LBStrategyRandom = LBStrategy(0) - LBStrategyPH = LBStrategy(-1) + LBStrategyNone = LBStrategy(iota) + LBStrategyP2 + LBStrategyPH + LBStrategyFirst + LBStrategyRandom ) -const DefaultLBStrategy = LBStrategy(2) +const DefaultLBStrategy = LBStrategyP2 type ServersInfo struct { sync.RWMutex @@ -208,12 +211,14 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo { } var candidate int switch serversInfo.lbStrategy { - case -1: // First half + case LBStrategyFirst: + candidate = 0 + case LBStrategyPH: candidate = rand.Intn(Max(Min(serversCount, 2), serversCount/2)) - case 0: // Random + case LBStrategyRandom: candidate = rand.Intn(serversCount) - default: // First N - candidate = rand.Intn(int(serversInfo.lbStrategy)) % serversCount + default: + candidate = rand.Intn(Min(serversCount, 2)) } serverInfo := serversInfo.inner[candidate] dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value()))