优化负载均衡,当只有一个节点的时候,不再启动健康检查.
This commit is contained in:
@ -36,6 +36,7 @@ type Group struct {
|
|||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
last *Backend
|
last *Backend
|
||||||
debug bool
|
debug bool
|
||||||
|
bks []*Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGroup(selectType int, configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger, debug bool) Group {
|
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,
|
dr: dr,
|
||||||
lock: &sync.Mutex{},
|
lock: &sync.Mutex{},
|
||||||
debug: debug,
|
debug: debug,
|
||||||
|
bks: bks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (g *Group) Select(srcAddr string, onlyHa bool) (addr string) {
|
func (g *Group) Select(srcAddr string, onlyHa bool) (addr string) {
|
||||||
|
if len(g.bks) == 1 {
|
||||||
|
return g.bks[0].Address
|
||||||
|
}
|
||||||
if onlyHa {
|
if onlyHa {
|
||||||
g.lock.Lock()
|
g.lock.Lock()
|
||||||
defer g.lock.Unlock()
|
defer g.lock.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user