lb

package
v0.0.0-...-4a7b1af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2018 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SELECT_ROUNDROBIN = iota
	SELECT_LEASTCONN
	SELECT_HASH
	SELECT_WEITHT
	SELECT_LEASTTIME
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	BackendConfig
	BackendControl
	sync.RWMutex
	// contains filtered or unexported fields
}

Backend structure

func NewBackend

func NewBackend(backendConfig BackendConfig, dr *dnsx.DomainResolver, log *log.Logger) (*Backend, error)

func (*Backend) DecreaseConns

func (b *Backend) DecreaseConns()

func (*Backend) IncreasConns

func (b *Backend) IncreasConns()

func (*Backend) StartHeartCheck

func (b *Backend) StartHeartCheck()

func (*Backend) StopHeartCheck

func (b *Backend) StopHeartCheck()

type BackendConfig

type BackendConfig struct {
	Address string

	ActiveAfter   int
	InactiveAfter int
	Weight        int

	Timeout   time.Duration
	RetryTime time.Duration

	IsMuxCheck  bool
	ConnFactory func(address string, timeout time.Duration) (net.Conn, error)
}

BackendConfig it's the configuration loaded

type BackendControl

type BackendControl struct {
	Failed bool // The last request failed
	Active bool

	InactiveTries int
	ActiveTries   int

	Connections int

	ConnectUsedMillisecond int
	// contains filtered or unexported fields
}

BackendControl keep the control data

type Backends

type Backends []*Backend

type BackendsConfig

type BackendsConfig []*BackendConfig

type Group

type Group struct {
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(selectType int, configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger, debug bool) Group

func (*Group) ActiveCount

func (g *Group) ActiveCount() (count int)

func (*Group) Backends

func (g *Group) Backends() []*Backend

func (*Group) DecreaseConns

func (g *Group) DecreaseConns(addr string)

func (*Group) IncreasConns

func (g *Group) IncreasConns(addr string)

func (*Group) IsActive

func (g *Group) IsActive() bool

func (*Group) Reset

func (g *Group) Reset(addrs []string)

func (*Group) Select

func (g *Group) Select(srcAddr string, onlyHa bool) (addr string)

func (*Group) Stop

func (g *Group) Stop()

type Hash

type Hash struct {
	sync.Mutex
	// contains filtered or unexported fields
}

########################Hash##########################

func (*Hash) ActiveCount

func (h *Hash) ActiveCount() (count int)

func (*Hash) Backends

func (h *Hash) Backends() []*Backend

func (*Hash) DecreaseConns

func (h *Hash) DecreaseConns(addr string)

func (*Hash) IncreasConns

func (h *Hash) IncreasConns(addr string)

func (*Hash) IsActive

func (h *Hash) IsActive() bool

func (*Hash) Reset

func (h *Hash) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)

func (*Hash) Select

func (h *Hash) Select(srcAddr string) (addr string)

func (*Hash) SelectBackend

func (h *Hash) SelectBackend(srcAddr string) (b *Backend)

func (*Hash) Stop

func (h *Hash) Stop()

type LeastConn

type LeastConn struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*LeastConn) ActiveCount

func (lc *LeastConn) ActiveCount() (count int)

func (*LeastConn) Backends

func (lc *LeastConn) Backends() []*Backend

func (*LeastConn) DecreaseConns

func (lc *LeastConn) DecreaseConns(addr string)

func (*LeastConn) IncreasConns

func (lc *LeastConn) IncreasConns(addr string)

func (*LeastConn) IsActive

func (lc *LeastConn) IsActive() bool

func (*LeastConn) Reset

func (lc *LeastConn) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)

func (*LeastConn) Select

func (lc *LeastConn) Select(srcAddr string) (addr string)

func (*LeastConn) SelectBackend

func (lc *LeastConn) SelectBackend(srcAddr string) (b *Backend)

func (*LeastConn) Stop

func (lc *LeastConn) Stop()

type LeastTime

type LeastTime struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*LeastTime) ActiveCount

func (lt *LeastTime) ActiveCount() (count int)

func (*LeastTime) Backends

func (lt *LeastTime) Backends() []*Backend

func (*LeastTime) DecreaseConns

func (lt *LeastTime) DecreaseConns(addr string)

func (*LeastTime) IncreasConns

func (lt *LeastTime) IncreasConns(addr string)

func (*LeastTime) IsActive

func (lt *LeastTime) IsActive() bool

func (*LeastTime) Reset

func (lt *LeastTime) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)

func (*LeastTime) Select

func (lt *LeastTime) Select(srcAddr string) (addr string)

func (*LeastTime) SelectBackend

func (lt *LeastTime) SelectBackend(srcAddr string) (b *Backend)

func (*LeastTime) Stop

func (lt *LeastTime) Stop()

type RoundRobin

type RoundRobin struct {
	sync.Mutex
	// contains filtered or unexported fields
}

########################RoundRobin##########################

func (*RoundRobin) ActiveCount

func (r *RoundRobin) ActiveCount() (count int)

func (*RoundRobin) Backends

func (r *RoundRobin) Backends() []*Backend

func (*RoundRobin) DecreaseConns

func (r *RoundRobin) DecreaseConns(addr string)

func (*RoundRobin) IncreasConns

func (r *RoundRobin) IncreasConns(addr string)

func (*RoundRobin) IsActive

func (r *RoundRobin) IsActive() bool

func (*RoundRobin) Reset

func (r *RoundRobin) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)

func (*RoundRobin) Select

func (r *RoundRobin) Select(srcAddr string) (addr string)

func (*RoundRobin) SelectBackend

func (r *RoundRobin) SelectBackend(srcAddr string) (b *Backend)

func (*RoundRobin) Stop

func (r *RoundRobin) Stop()

type Selector

type Selector interface {
	Select(srcAddr string) (addr string)
	SelectBackend(srcAddr string) (b *Backend)
	IncreasConns(addr string)
	DecreaseConns(addr string)
	Stop()
	Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)
	IsActive() bool
	ActiveCount() (count int)
	Backends() (bs []*Backend)
}

func NewHash

func NewHash(backends Backends, log *log.Logger, debug bool) Selector

func NewLeastConn

func NewLeastConn(backends []*Backend, log *log.Logger, debug bool) Selector

func NewLeastTime

func NewLeastTime(backends []*Backend, log *log.Logger, debug bool) Selector

func NewRoundRobin

func NewRoundRobin(backends Backends, log *log.Logger, debug bool) Selector

func NewWeight

func NewWeight(backends Backends, log *log.Logger, debug bool) Selector

type Weight

type Weight struct {
	sync.Mutex
	// contains filtered or unexported fields
}

########################Weight##########################

func (*Weight) ActiveCount

func (w *Weight) ActiveCount() (count int)

func (*Weight) Backends

func (w *Weight) Backends() []*Backend

func (*Weight) DecreaseConns

func (w *Weight) DecreaseConns(addr string)

func (*Weight) IncreasConns

func (w *Weight) IncreasConns(addr string)

func (*Weight) IsActive

func (w *Weight) IsActive() bool

func (*Weight) Reset

func (w *Weight) Reset(configs BackendsConfig, dr *dnsx.DomainResolver, log *log.Logger)

func (*Weight) Select

func (w *Weight) Select(srcAddr string) (addr string)

func (*Weight) SelectBackend

func (w *Weight) SelectBackend(srcAddr string) (b *Backend)

func (*Weight) Stop

func (w *Weight) Stop()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL