algorithm

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 10 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, w *http.ResponseWriter) *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, w *http.ResponseWriter) *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

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, w *http.ResponseWriter) *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, w *http.ResponseWriter) *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,
	w *http.ResponseWriter,
) *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, w *http.ResponseWriter) *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 SessionAffinity added in v0.4.4

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

func NewSessionAffinity added in v0.4.4

func NewSessionAffinity() *SessionAffinity

NewSessionAffinity creates a new sticky session manager with default settings

func (*SessionAffinity) Name added in v0.4.4

func (ss *SessionAffinity) Name() string

Name returns the identifier of the session affinity

func (*SessionAffinity) NextServer added in v0.4.4

func (ss *SessionAffinity) NextServer(pool ServerPool, r *http.Request, w *http.ResponseWriter) *Server

NextServer selects the appropriate backend server based on session stickiness

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, w *http.ResponseWriter) *Server

Jump to

Keyboard shortcuts

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