algorithm

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdaptiveLoadBalancer

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

func NewAdaptiveLoadBalancer

func NewAdaptiveLoadBalancer() *AdaptiveLoadBalancer

func (*AdaptiveLoadBalancer) NextServer

func (alb *AdaptiveLoadBalancer) NextServer(pool ServerPool, r *http.Request) *Server

func (*AdaptiveLoadBalancer) RecordMetrics

func (alb *AdaptiveLoadBalancer) RecordMetrics(algorithm string, responseTime time.Duration, isError bool)

type Algorithm

type Algorithm interface {
	NextServer(pool ServerPool, r *http.Request) *Server
	Name() string
}

func CreateAlgorithm

func CreateAlgorithm(name string) Algorithm

type AlgorithmStats

type AlgorithmStats struct {
	ResponseTimes []time.Duration
	ErrorCount    int
	RequestCount  int
}

type BoundedLeastConnections

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

func NewBoundedLeastConnections

func NewBoundedLeastConnections(sampleSize int) *BoundedLeastConnections

func (*BoundedLeastConnections) Name

func (blc *BoundedLeastConnections) Name() string

func (*BoundedLeastConnections) NextServer

func (blc *BoundedLeastConnections) NextServer(pool ServerPool, _ *http.Request) *Server

type IPHash

type IPHash struct{}

func (*IPHash) Name

func (ih *IPHash) Name() string

func (*IPHash) NextServer

func (ih *IPHash) NextServer(pool ServerPool, r *http.Request) *Server

type LeastConnections

type LeastConnections struct{}

func (*LeastConnections) Name

func (lc *LeastConnections) Name() string

func (*LeastConnections) NextServer

func (lc *LeastConnections) NextServer(pool ServerPool, _ *http.Request) *Server

type LeastResponseTime

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

func NewLeastResponseTime

func NewLeastResponseTime() *LeastResponseTime

func (*LeastResponseTime) Name

func (lrt *LeastResponseTime) Name() string

func (*LeastResponseTime) NextServer

func (lrt *LeastResponseTime) NextServer(pool ServerPool, _ *http.Request) *Server

func (*LeastResponseTime) UpdateResponseTime

func (lrt *LeastResponseTime) UpdateResponseTime(serverURL string, duration time.Duration)

type RoundRobin

type RoundRobin struct{}

func (*RoundRobin) Name

func (rr *RoundRobin) Name() string

func (*RoundRobin) NextServer

func (rr *RoundRobin) NextServer(pool ServerPool, _ *http.Request) *Server

type Server

type Server struct {
	URL              string
	Weight           int
	CurrentWeight    atomic.Int32
	ConnectionCount  int32
	MaxConnections   int32
	Alive            atomic.Bool
	LastResponseTime time.Duration
}

func (*Server) CanAcceptConnection

func (b *Server) CanAcceptConnection() bool

type ServerPool

type ServerPool interface {
	GetBackends() []*Server
	GetCurrentIndex() uint64
	SetCurrentIndex(idx uint64)
}

type WeightedRoundRobin

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

func (*WeightedRoundRobin) Name

func (wrr *WeightedRoundRobin) Name() string

func (*WeightedRoundRobin) NextServer

func (wrr *WeightedRoundRobin) NextServer(pool ServerPool, _ *http.Request) *Server

Jump to

Keyboard shortcuts

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