Skip to content

Commit

Permalink
优化负载均衡,当只有一个节点的时候,不再启动健康检查.
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Sep 18, 2018
1 parent 08b3715 commit 42d18ca
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions utils/lb/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 42d18ca

Please sign in to comment.