loadbalance

package
v0.0.0-...-5dc8409 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package loadbalance is a way to load balance service nodes

Index

Constants

View Source
const (
	StrategyRoundRobin        = "RoundRobin"
	StrategyRandom            = "Random"
	StrategySessionStickiness = "SessionStickiness"
	StrategyLatency           = "WeightedResponse"
)

constant strings for load balance variables

View Source
const (
	ZoneAware = "zoneaware"
)

constant string for zoneaware

Variables

View Source
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

View Source
var (
	// SessionCache session cache variable
	SessionCache *cache.Cache
	// SuccessiveFailureCount success and failure count
	SuccessiveFailureCount map[string]int
)
View Source
var (
	// DefaultSelector is the object of selector
	DefaultSelector selector.Selector
)

Filters is a map of string and array of *registry.MicroServiceInstance

Functions

func Delete

func Delete(sid string)

Delete for deleting the sid

func Enable

func Enable() error

Enable function is for to enable load balance strategy

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

func FindingAvgLatency(metadata string) (avgMap map[string]time.Duration, protocol string)

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

func InstallFilter(name string, f selector.Filter)

InstallFilter install filter

func InstallStrategy

func InstallStrategy(name string, strategy func([]*registry.MicroServiceInstance, interface{}) selector.Next)

InstallStrategy install strategy

func Save

func Save(sid string, addr string, timeOut time.Duration)

Save for setting the service id, address, timeout

func SessionStickiness

func SessionStickiness(instances []*registry.MicroServiceInstance, metadata interface{}) selector.Next

SessionStickiness is a SessionStickiness strategy algorithm for node selection

func SetLatency

func SetLatency(duration time.Duration, addr, microServiceNameAndProtocol string)

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

type ByDuration []time.Duration

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)

Jump to

Keyboard shortcuts

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