Documentation ¶
Overview ¶
Package loadbalance is a way to load balance service nodes
Index ¶
- Constants
- Variables
- func Delete(sid string)
- func Enable() error
- func FilterAvailableZoneAffinity(old []*registry.MicroServiceInstance) []*registry.MicroServiceInstance
- func FindingAvgLatency(metadata string) (avgMap map[string]time.Duration, protocol string)
- func GetStrategyPlugin(name string) (func([]*registry.MicroServiceInstance, interface{}) selector.Next, error)
- func InstallFilter(name string, f selector.Filter)
- func InstallStrategy(name string, ...)
- func Save(sid string, addr string, timeOut time.Duration)
- func SessionStickiness(instances []*registry.MicroServiceInstance, metadata interface{}) selector.Next
- func SetLatency(duration time.Duration, addr, microServiceNameAndProtocol string)
- func SortingLatencyDuration(serviceAndProtocol string, avgLatencyMap map[string]time.Duration) string
- func WeightedResponse(instances []*registry.MicroServiceInstance, serviceAndProtocol interface{}) selector.Next
- type ByDuration
Constants ¶
const ( StrategyRoundRobin = "RoundRobin" StrategyRandom = "Random" StrategySessionStickiness = "SessionStickiness" StrategyLatency = "WeightedResponse" )
constant strings for load balance variables
const (
ZoneAware = "zoneaware"
)
constant string for zoneaware
Variables ¶
var ( //LatencyMap key is the combination of instance addr and microservice name separated by "/" LatencyMap map[string][]time.Duration //maintain different locks since multiple goroutine access the map LatencyMapRWMutex sync.RWMutex )
variables for latency map, rest and highway requests count
var ( // SessionCache session cache variable SessionCache *cache.Cache // SuccessiveFailureCount success and failure count SuccessiveFailureCount map[string]int )
var ( // DefaultSelector is the object of selector DefaultSelector selector.Selector )
var Filters map[string]func([]*registry.MicroServiceInstance) []*registry.MicroServiceInstance = make(map[string]func([]*registry.MicroServiceInstance) []*registry.MicroServiceInstance)
Filters is a map of string and array of *registry.MicroServiceInstance
Functions ¶
func FilterAvailableZoneAffinity ¶
func FilterAvailableZoneAffinity(old []*registry.MicroServiceInstance) []*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 FindingAvgLatency ¶
FindingAvgLatency Calculating the average latency for each instance using the statistics collected, key is addr/service/protocol
func GetStrategyPlugin ¶
func GetStrategyPlugin(name string) (func([]*registry.MicroServiceInstance, interface{}) selector.Next, error)
GetStrategyPlugin get strategy plugin
func InstallFilter ¶
InstallFilter install filter
func InstallStrategy ¶
func InstallStrategy(name string, strategy func([]*registry.MicroServiceInstance, interface{}) selector.Next)
InstallStrategy install strategy
func SessionStickiness ¶
func SessionStickiness(instances []*registry.MicroServiceInstance, metadata interface{}) selector.Next
SessionStickiness is a SessionStickiness strategy algorithm for node selection
func SetLatency ¶
SetLatency for each requests
func SortingLatencyDuration ¶
func SortingLatencyDuration(serviceAndProtocol string, avgLatencyMap map[string]time.Duration) string
SortingLatencyDuration sorting the average latencies recored for each instance and returning the instance addr which has the least latency
func WeightedResponse ¶
func WeightedResponse(instances []*registry.MicroServiceInstance, serviceAndProtocol interface{}) selector.Next
WeightedResponse is a strategy plugin,interface must be a service/protocol string
Types ¶
type ByDuration ¶
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)