balancer

package
v0.0.0-...-0714773 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LeastConnected

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

LeastConnected based loadbalancing interface for statistics

func (LeastConnected) Len

func (s LeastConnected) Len() int

func (LeastConnected) Less

func (s LeastConnected) Less(i, j int) bool

Less implements LeastConnected based loadbalancing by sorting based on leastconnected counter

func (LeastConnected) Swap

func (s LeastConnected) Swap(i, j int)

type LeastTraffic

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

LeastTraffic based loadbalancing

func (LeastTraffic) Len

func (s LeastTraffic) Len() int

func (LeastTraffic) Less

func (s LeastTraffic) Less(i, j int) bool

Less implements LeastTraffic based loadbalancing by sorting based on leasttraffic counter

func (LeastTraffic) Swap

func (s LeastTraffic) Swap(i, j int)

type Preference

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

Preference based loadbalancing interface for statistic

func (Preference) Len

func (s Preference) Len() int

func (Preference) Less

func (s Preference) Less(i, j int) bool

Less implements preference based loadbalancing by sorting based on Preference counter

func (Preference) Swap

func (s Preference) Swap(i, j int)

type ResponseTime

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

ResponseTime based loadbalancing interface for statistics

func (ResponseTime) Len

func (s ResponseTime) Len() int

func (ResponseTime) Less

func (s ResponseTime) Less(i, j int) bool

Less implements ResponseTime based loadbalancing by sorting based on ResponseTime counter

func (ResponseTime) Swap

func (s ResponseTime) Swap(i, j int)

type RoundRobin

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

RoundRobin sorts records by Round robin

func (RoundRobin) Len

func (s RoundRobin) Len() int

func (RoundRobin) Less

func (s RoundRobin) Less(i, j int) bool

Less implements RoundRobin based loadbalancing by sorting based on selected counter

func (RoundRobin) Swap

func (s RoundRobin) Swap(i, j int)

type Statistics

type Statistics struct {
	*sync.RWMutex
	UUID              string    `json:"uuid"`
	ClientsConnected  int64     `json:"clientsconnected"`
	ClientsConnects   int64     `json:"clientsconnects"`
	RX                int64     `json:"rx"`
	TX                int64     `json:"tx"`
	Preference        int       `json:"preference"`
	Topology          []string  `json:"topology"`
	TimeCounter       chan bool `json:"-"`         // counts the elements
	TimeTimer         int       `json:"timetimer"` // time to keep elements
	ResponseTimeValue []float64 `json:"responsetimevalue"`
	Weighted          int       `json:"weighted"` // weighted value
}

Statistics used to determain balancing

func FirstAvailable

func FirstAvailable(s []Statistics) []Statistics

FirstAvailable Balance based on nothing, returns the first host entry this is used to limit the output to 1 host

func MultiSort

func MultiSort(s []Statistics, ip string, sticky string, mode string) ([]Statistics, error)

MultiSort sorts statistics based on multiple modes

func NewStatistics

func NewStatistics(UUID string, counterSize int) *Statistics

NewStatistics returns new statistics

func Random

func Random(s []Statistics) []Statistics

Random implements the Random balance type, by randomizing the array provided

func Sort

func Sort(s []Statistics, ip string, sticky string, mode string) ([]Statistics, error)

Sort sorts statistics based on value. ID can be a IP for ip based loadbalancing. ID van be sessionID for stickyness based loadbalancing.

func Sticky

func Sticky(s []Statistics, id string) []Statistics

Sticky Balance based on Stickiness, the provided ID should always match the same node

func Topology

func Topology(s []Statistics, ip string) []Statistics

Topology Balance based on Topology, this only returns stats where the ip matches the topolology

func WeighCalculation

func WeighCalculation(s []Statistics) []Statistics

WeighCalculation implements a weighted form of loadbalancing

func (*Statistics) ClientsConnectedAdd

func (s *Statistics) ClientsConnectedAdd(i int64)

ClientsConnectedAdd adds a client to the counter

func (*Statistics) ClientsConnectedGet

func (s *Statistics) ClientsConnectedGet() int64

ClientsConnectedGet returns the clients connected

func (*Statistics) ClientsConnectedSet

func (s *Statistics) ClientsConnectedSet(count int64)

ClientsConnectedSet adds a client to the counter

func (*Statistics) ClientsConnectedSub

func (s *Statistics) ClientsConnectedSub(i int64)

ClientsConnectedSub adds a client to the counter

func (*Statistics) ClientsConnectsAdd

func (s *Statistics) ClientsConnectsAdd(i int64)

ClientsConnectsAdd adds a client to the counter

func (*Statistics) ClientsConnectsGet

func (s *Statistics) ClientsConnectsGet() int64

ClientsConnectsGet returns the clients requests

func (*Statistics) ClientsConnectsSet

func (s *Statistics) ClientsConnectsSet(count int64)

ClientsConnectsSet adds a client to the counter

func (*Statistics) ClientsConnectsSub

func (s *Statistics) ClientsConnectsSub(i int64)

ClientsConnectsSub adds a client to the counter

func (*Statistics) RXAdd

func (s *Statistics) RXAdd(rx int64)

RXAdd adds a client to the counter

func (*Statistics) RXGet

func (s *Statistics) RXGet() int64

RXGet returns received traffic

func (*Statistics) Reset

func (s *Statistics) Reset()

Reset zero's the statistic values

func (*Statistics) ResponseTimeAdd

func (s *Statistics) ResponseTimeAdd(f float64)

ResponseTimeAdd adds a response time to the array, and cycles through them if full

func (*Statistics) ResponseTimeGet

func (s *Statistics) ResponseTimeGet() float64

ResponseTimeGet gets current averate response time

func (*Statistics) ResponseTimeValueGet

func (s *Statistics) ResponseTimeValueGet() []float64

ResponseTimeValueGet returns the responsetime values

func (*Statistics) ResponseTimeValueMerge

func (s *Statistics) ResponseTimeValueMerge(f []float64)

ResponseTimeValueMerge merges 2 response time arrays

func (*Statistics) SetWeighted

func (s *Statistics) SetWeighted(w int)

SetWeighted adds a weight to the counter

func (*Statistics) TXAdd

func (s *Statistics) TXAdd(tx int64)

TXAdd adds a client to the counter

func (*Statistics) TXGet

func (s *Statistics) TXGet() int64

TXGet returns sent traffic

func (*Statistics) TimeCounterAdd

func (s *Statistics) TimeCounterAdd()

TimeCounterAdd counter for entriest per X seconds

func (*Statistics) TimeCounterGet

func (s *Statistics) TimeCounterGet() int

TimeCounterGet gets current count of the timer

func (*Statistics) UUIDGet

func (s *Statistics) UUIDGet() string

UUIDGet returns the UUID

type Weighted

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

Weighted based loadbalancing interface for statistic

func (Weighted) Len

func (s Weighted) Len() int

func (Weighted) Less

func (s Weighted) Less(i, j int) bool

Less implements preference based loadbalancing by sorting based on Preference counter

func (Weighted) Swap

func (s Weighted) Swap(i, j int)

Jump to

Keyboard shortcuts

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