Documentation ¶
Overview ¶
Package loadbalancer is client side load balancer
Index ¶
- Constants
- Variables
- func BuildKey(microServiceName, tags, protocol string) string
- func CalculateAvgLatency()
- func DeleteSuccessiveFailureCount(cookieValue string)
- func Enable() error
- func FilterAvailableZoneAffinity(old []*registry.MicroServiceInstance, c []*Criteria) []*registry.MicroServiceInstance
- func FilterByMetadata(old []*registry.MicroServiceInstance, c []*Criteria) []*registry.MicroServiceInstance
- func GetStrategyPlugin(name string) (func() Strategy, error)
- func GetSuccessiveFailureCount(cookieValue string) int
- func IncreaseSuccessiveFailureCount(cookieValue string)
- func InstallFilter(name string, f Filter)
- func InstallStrategy(name string, s func() Strategy)
- func ResetSuccessiveFailureMap()
- func SetLatency(latency time.Duration, addr, microServiceName string, tags utiltags.Tags, ...)
- func SortLatency()
- type ByDuration
- type Criteria
- type Filter
- type LBError
- type ProtocolStats
- type RandomStrategy
- type RoundRobinStrategy
- type SessionStickinessStrategy
- type Strategy
- type WeightedResponseStrategy
Constants ¶
const ( StrategyRoundRobin = "RoundRobin" StrategyRandom = "Random" StrategySessionStickiness = "SessionStickiness" StrategyLatency = "WeightedResponse" OperatorEqual = "=" OperatorGreater = ">" OperatorSmaller = "<" OperatorPattern = "Pattern" )
constant strings for load balance variables
const (
ZoneAware = "zoneaware"
)
constant string for zoneaware
Variables ¶
var ( //ProtocolStatsMap saves all stats for all service's protocol, one protocol has a lot of instances ProtocolStatsMap = make(map[string][]*ProtocolStats) //maintain different locks since multiple goroutine access the map LatencyMapRWMutex sync.RWMutex )
variables for latency map, rest and highway requests count
var ( // ErrNoneAvailableInstance is to represent load balance error ErrNoneAvailableInstance = LBError{Message: "None available instance"} )
var Filters = make(map[string]Filter)
Filters is a map of string and array of *registry.MicroServiceInstance
Functions ¶
func CalculateAvgLatency ¶
func CalculateAvgLatency()
CalculateAvgLatency Calculating the average latency for each instance using the statistics collected, key is addr/service/protocol
func DeleteSuccessiveFailureCount ¶
func DeleteSuccessiveFailureCount(cookieValue string)
DeleteSuccessiveFailureCount deleting cookie from failure count map
func FilterAvailableZoneAffinity ¶
func FilterAvailableZoneAffinity(old []*registry.MicroServiceInstance, c []*Criteria) []*registry.MicroServiceInstance
FilterAvailableZoneAffinity is a region and zone based Select Filter which will Do the selection of instance in the same region and zone, if not Do the selection of instance in any zone in same region , if not Do the selection of instance in any zone of any region
func FilterByMetadata ¶
func FilterByMetadata(old []*registry.MicroServiceInstance, c []*Criteria) []*registry.MicroServiceInstance
FilterByMetadata filter instances based meta data
func GetStrategyPlugin ¶
GetStrategyPlugin get strategy plugin
func GetSuccessiveFailureCount ¶
GetSuccessiveFailureCount get failure count
func IncreaseSuccessiveFailureCount ¶
func IncreaseSuccessiveFailureCount(cookieValue string)
IncreaseSuccessiveFailureCount increase failure count
func InstallStrategy ¶
InstallStrategy install strategy
func ResetSuccessiveFailureMap ¶
func ResetSuccessiveFailureMap()
ResetSuccessiveFailureMap make map again
Types ¶
type ByDuration ¶
type ByDuration []*ProtocolStats
ByDuration is for calculating the duration
func (ByDuration) Len ¶
func (a ByDuration) Len() int
func (ByDuration) Less ¶
func (a ByDuration) Less(i, j int) bool
func (ByDuration) Swap ¶
func (a ByDuration) Swap(i, j int)
type Filter ¶
type Filter func(instances []*registry.MicroServiceInstance, criteria []*Criteria) []*registry.MicroServiceInstance
Filter receive instances and criteria, it will filter instances based on criteria you defined,criteria is optional, you can give nil for it
type ProtocolStats ¶
ProtocolStats store protocol stats
func (*ProtocolStats) CalculateAverageLatency ¶
func (ps *ProtocolStats) CalculateAverageLatency()
CalculateAverageLatency make avg latency
func (*ProtocolStats) SaveLatency ¶
func (ps *ProtocolStats) SaveLatency(l time.Duration)
SaveLatency save latest 10 record
type RandomStrategy ¶
type RandomStrategy struct {
// contains filtered or unexported fields
}
RandomStrategy is strategy
func (*RandomStrategy) Pick ¶
func (r *RandomStrategy) Pick() (*registry.MicroServiceInstance, error)
Pick return instance
func (*RandomStrategy) ReceiveData ¶
func (r *RandomStrategy) ReceiveData(instances []*registry.MicroServiceInstance, serviceName, protocol, sessionID string)
ReceiveData receive data
type RoundRobinStrategy ¶
type RoundRobinStrategy struct {
// contains filtered or unexported fields
}
RoundRobinStrategy is strategy
func (*RoundRobinStrategy) Pick ¶
func (r *RoundRobinStrategy) Pick() (*registry.MicroServiceInstance, error)
Pick return instance
func (*RoundRobinStrategy) ReceiveData ¶
func (r *RoundRobinStrategy) ReceiveData(instances []*registry.MicroServiceInstance, serviceKey, protocol, sessionID string)
ReceiveData receive data
type SessionStickinessStrategy ¶
type SessionStickinessStrategy struct {
// contains filtered or unexported fields
}
SessionStickinessStrategy is strategy
func (*SessionStickinessStrategy) Pick ¶
func (r *SessionStickinessStrategy) Pick() (*registry.MicroServiceInstance, error)
Pick return instance
func (*SessionStickinessStrategy) ReceiveData ¶
func (r *SessionStickinessStrategy) ReceiveData(instances []*registry.MicroServiceInstance, serviceName, protocol, sessionID string)
ReceiveData receive data
type Strategy ¶
type Strategy interface { ReceiveData(instances []*registry.MicroServiceInstance, serviceKey, protocol, sessionID string) Pick() (*registry.MicroServiceInstance, error) }
Strategy is load balancer algorithm , call Pick to return one instance
type WeightedResponseStrategy ¶
type WeightedResponseStrategy struct {
// contains filtered or unexported fields
}
WeightedResponseStrategy is a strategy plugin
func (*WeightedResponseStrategy) Pick ¶
func (r *WeightedResponseStrategy) Pick() (*registry.MicroServiceInstance, error)
Pick return instance
func (*WeightedResponseStrategy) ReceiveData ¶
func (r *WeightedResponseStrategy) ReceiveData(instances []*registry.MicroServiceInstance, serviceKey, protocol, sessionID string)
ReceiveData receive data