优化负载均衡,当只有一个节点的时候,不再启动健康检查.

This commit is contained in:
arraykeys@gmail.com
2018-09-18 16:08:59 +08:00
parent 08b3715bda
commit 42d18ca1d3

View File

@ -36,6 +36,7 @@ type Group struct {
lock *sync.Mutex
last *Backend
debug bool
bks []*Backend
}
func NewGroup(selectType int, configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger, debug bool) Group {
@ -68,9 +69,13 @@ func NewGroup(selectType int, configs BackendsConfig, dr *dnsx.DomainResolver, l
dr: dr,
lock: &sync.Mutex{},
debug: debug,
bks: bks,
}
}
func (g *Group) Select(srcAddr string, onlyHa bool) (addr string) {
if len(g.bks) == 1 {
return g.bks[0].Address
}
if onlyHa {
g.lock.Lock()
defer g.lock.Unlock()