Documentation
¶
Index ¶
- Constants
- Variables
- func CheckHealth(b *NodeBalancer, host string, config config.HealthCheck)
- func DoHealthCheck(v *Item, host string, config config.HealthCheck)
- func GetUpstreamNode(name string, requestURL url.URL, defaultHost string) string
- func Init(name string, config config.Upstream)
- func InitIpHash(name string, config config.Upstream, enableHealthchecks bool)
- func InitLeastConnection(name string, config config.Upstream, enableHealthchecks bool)
- func InitRandom(name string, config config.Upstream, enableHealthchecks bool)
- func InitRoundRobin(name string, config config.Upstream, enableHealthchecks bool)
- type Balancer
- type IpHashBalancer
- type Item
- type LeastConnectionsBalancer
- type LoadBalancing
- type NodeBalancer
- type RandomBalancer
- type RoundRobinBalancer
Constants ¶
const HealthCheckInterval time.Duration = 30 * time.Second // TODO: make it customizable
HealthCheckInterval - Health Check Frequency.
const LeastConnectionsResetInterval time.Duration = 5 * time.Minute // TODO: make it customizable
LeastConnectionsResetInterval - How often reset internal counter for Least Connection LoadBalancer.
Variables ¶
var ErrNoAvailableItem = errors.New("no item is available")
ErrNoAvailableItem no item is available.
Functions ¶
func CheckHealth ¶ added in v1.3.1
func CheckHealth(b *NodeBalancer, host string, config config.HealthCheck)
CheckHealth - Periodic check on nodes status.
func DoHealthCheck ¶ added in v1.3.1
func DoHealthCheck(v *Item, host string, config config.HealthCheck)
func GetUpstreamNode ¶ added in v1.3.1
GetUpstreamNode - Returns backend server using current algorithm.
func InitIpHash ¶ added in v1.3.1
InitIpHash - Initialise the LB algorithm for ip-hash selection.
func InitLeastConnection ¶ added in v1.3.1
InitLeastConnection - Initialise the LB algorithm for least-connection selection.
func InitRandom ¶ added in v1.3.1
InitRandom - Initialise the LB algorithm for random selection.
Types ¶
type Balancer ¶ added in v1.3.1
type Balancer interface {
GetHealthyNodes() []Item
Pick(requestURL string) (string, error)
GetNodeBalancer() *NodeBalancer
}
Balancer - Represents a Load Balancer interface.
type IpHashBalancer ¶ added in v1.3.1
type IpHashBalancer struct {
NodeBalancer
// contains filtered or unexported fields
}
IpHashBalancer instance.
func NewIpHashBalancer ¶ added in v1.3.1
func NewIpHashBalancer(name string, items []Item) *IpHashBalancer
NewIpHashBalancer - Creates a new instance.
type LeastConnectionsBalancer ¶ added in v1.3.1
type LeastConnectionsBalancer struct {
NodeBalancer
// contains filtered or unexported fields
}
LeastConnectionsBalancer instance.
func NewLeastConnectionsBalancer ¶ added in v1.3.1
func NewLeastConnectionsBalancer(name string, items []Item) *LeastConnectionsBalancer
NewLeastConnectionsBalancer - Creates a new instance.
func (*LeastConnectionsBalancer) Pick ¶ added in v1.3.1
func (b *LeastConnectionsBalancer) Pick(requestURL string) (string, error)
Pick - Chooses next available item.
func (*LeastConnectionsBalancer) ResetCounter ¶ added in v1.3.1
func (b *LeastConnectionsBalancer) ResetCounter(period time.Duration)
ResetCounter - Resets internal connection counters periodically.
type LoadBalancing ¶ added in v1.3.1
LoadBalancing - Contains the multiple instances for the active servers.
type NodeBalancer ¶ added in v1.3.1
NodeBalancer - Core structure for a load balancer.
func (*NodeBalancer) GetHealthyNodes ¶ added in v1.3.1
func (b *NodeBalancer) GetHealthyNodes() []Item
GetHealthyNodes - Retrieves healthy nodes. It locks internally: callers must NOT hold b.M when invoking it (nested RLock acquisition can deadlock with a pending writer).
func (*NodeBalancer) GetNodeBalancer ¶ added in v1.3.1
func (b *NodeBalancer) GetNodeBalancer() *NodeBalancer
GetNodeBalancer - Returns the embedded NodeBalancer, promoted to every concrete balancer type so Init* can health-check without a type assertion.
type RandomBalancer ¶ added in v1.3.1
type RandomBalancer struct {
NodeBalancer
// contains filtered or unexported fields
}
RandomBalancer instance.
func NewRandomBalancer ¶ added in v1.3.1
func NewRandomBalancer(name string, items []Item) *RandomBalancer
NewRandomBalancer - Creates a new instance.
type RoundRobinBalancer ¶ added in v1.3.1
type RoundRobinBalancer struct {
NodeBalancer
// contains filtered or unexported fields
}
RoundRobinBalancer instance.
func NewRoundRobinBalancer ¶ added in v1.3.1
func NewRoundRobinBalancer(name string, items []Item) *RoundRobinBalancer
NewRoundRobinBalancer - Creates a new instance.