Make the load-balancing strategy configurable

This commit is contained in:
Frank Denis 2018-02-04 21:23:39 +01:00
parent 88434fc39f
commit a43352e160
2 changed files with 31 additions and 5 deletions

View File

@ -22,11 +22,12 @@ type Config struct {
ServerNames []string `toml:"server_names"`
ListenAddresses []string `toml:"listen_addresses"`
Daemonize bool
ForceTCP bool `toml:"force_tcp"`
Timeout int `toml:"timeout_ms"`
CertRefreshDelay int `toml:"cert_refresh_delay"`
CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"`
BlockIPv6 bool `toml:"block_ipv6"`
ForceTCP bool `toml:"force_tcp"`
Timeout int `toml:"timeout_ms"`
CertRefreshDelay int `toml:"cert_refresh_delay"`
CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"`
LBStrategy string `toml:"lb_strategy"`
BlockIPv6 bool `toml:"block_ipv6"`
Cache bool
CacheSize int `toml:"cache_size"`
CacheNegTTL uint32 `toml:"cache_neg_ttl"`
@ -174,6 +175,22 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
if len(config.ListenAddresses) == 0 {
dlog.Debug("No local IP/port configured")
}
lbStrategy := DefaultLBStrategy
switch strings.ToLower(config.LBStrategy) {
case "p2":
lbStrategy = LBStrategyP2
case "ph":
lbStrategy = LBStrategyPH
case "fastest":
lbStrategy = LBStrategyFastest
case "random":
lbStrategy = LBStrategyRandom
default:
dlog.Warnf("Unknown load balancing strategy: [%s]", config.LBStrategy)
}
proxy.serversInfo.lbStrategy = lbStrategy
proxy.listenAddresses = config.ListenAddresses
proxy.daemonize = config.Daemonize
proxy.pluginBlockIPv6 = config.BlockIPv6

View File

@ -64,6 +64,15 @@ force_tcp = false
timeout = 2500
## Load-balancing strategy
## 'p2' = power of two choices (default)
## 'ph' = power of half the choices
## 'fastest' = only use the fastest server
## 'random' = uniform distribution across all available resolvers
# lb_strategy = 'p2'
## Log level (0-6, default: 2 - 0 is very verbose, 6 only contains fatal errors)
# log_level = 2