loadbalancer

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthCheckManager

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

HealthCheckManager manages health checks for backend servers

func NewHealthCheckManager

func NewHealthCheckManager() *HealthCheckManager

NewHealthCheckManager creates a new health check manager

func (*HealthCheckManager) Start

func (hcm *HealthCheckManager) Start(backend *route.NormalizedBackend) error

Start starts health checking for a backend

func (*HealthCheckManager) Stop

func (hcm *HealthCheckManager) Stop(backendID string) error

Stop stops health checking for a backend

func (*HealthCheckManager) StopAll

func (hcm *HealthCheckManager) StopAll() error

StopAll stops all health checks

type IPHash

type IPHash struct{}

IPHash implements IP hash load balancing

func NewIPHash

func NewIPHash() *IPHash

NewIPHash creates a new IP hash load balancer

func (*IPHash) OnRequestEnd

func (ih *IPHash) OnRequestEnd(backend *route.NormalizedBackend, server *service.Server)

OnRequestEnd is a no-op for IP hash

func (*IPHash) OnRequestStart

func (ih *IPHash) OnRequestStart(backend *route.NormalizedBackend, server *service.Server)

OnRequestStart is a no-op for IP hash

func (*IPHash) Select

func (ih *IPHash) Select(req *http.Request, backend *route.NormalizedBackend) (*service.Server, error)

Select chooses a server based on client IP hash

func (*IPHash) UpdateHealth

func (ih *IPHash) UpdateHealth(server *service.Server, healthy bool)

UpdateHealth is a no-op for IP hash

type LeastConnections

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

LeastConnections implements least-connections load balancing

func NewLeastConnections

func NewLeastConnections() *LeastConnections

NewLeastConnections creates a new least-connections load balancer

func (*LeastConnections) OnRequestEnd

func (lc *LeastConnections) OnRequestEnd(backend *route.NormalizedBackend, server *service.Server)

OnRequestEnd decrements the connection count

func (*LeastConnections) OnRequestStart

func (lc *LeastConnections) OnRequestStart(backend *route.NormalizedBackend, server *service.Server)

OnRequestStart increments the connection count

func (*LeastConnections) Select

func (lc *LeastConnections) Select(req *http.Request, backend *route.NormalizedBackend) (*service.Server, error)

Select chooses a server with the least number of active connections

func (*LeastConnections) UpdateHealth

func (lc *LeastConnections) UpdateHealth(server *service.Server, healthy bool)

UpdateHealth is a no-op for least-connections

type LoadBalancer

type LoadBalancer interface {
	// Select chooses a server instance from the backend
	Select(req *http.Request, backend *route.NormalizedBackend) (*service.Server, error)

	// UpdateHealth updates the health status of a server (optional)
	UpdateHealth(server *service.Server, healthy bool)

	// OnRequestStart is called when a request starts (for least-connections)
	OnRequestStart(backend *route.NormalizedBackend, server *service.Server)

	// OnRequestEnd is called when a request ends (for least-connections)
	OnRequestEnd(backend *route.NormalizedBackend, server *service.Server)
}

LoadBalancer defines the interface for load balancing algorithms

type Manager

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

Manager manages load balancers and health checks

func NewManager

func NewManager() *Manager

NewManager creates a new load balancer manager

func (*Manager) GetHealthCheckManager

func (m *Manager) GetHealthCheckManager() *HealthCheckManager

GetHealthCheckManager returns the health check manager

func (*Manager) GetLoadBalancer

func (m *Manager) GetLoadBalancer(algorithm string) LoadBalancer

GetLoadBalancer returns a load balancer for the specified algorithm

func (*Manager) StartHealthCheck

func (m *Manager) StartHealthCheck(backend *route.NormalizedBackend) error

StartHealthCheck starts health checking for a backend

func (*Manager) StopAllHealthChecks

func (m *Manager) StopAllHealthChecks() error

StopAllHealthChecks stops all health checks

func (*Manager) StopHealthCheck

func (m *Manager) StopHealthCheck(backendID string) error

StopHealthCheck stops health checking for a backend

type RoundRobin

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

RoundRobin implements round-robin load balancing

func NewRoundRobin

func NewRoundRobin() *RoundRobin

NewRoundRobin creates a new round-robin load balancer

func (*RoundRobin) OnRequestEnd

func (rr *RoundRobin) OnRequestEnd(backend *route.NormalizedBackend, server *service.Server)

OnRequestEnd is a no-op for round-robin

func (*RoundRobin) OnRequestStart

func (rr *RoundRobin) OnRequestStart(backend *route.NormalizedBackend, server *service.Server)

OnRequestStart is a no-op for round-robin

func (*RoundRobin) Select

func (rr *RoundRobin) Select(req *http.Request, backend *route.NormalizedBackend) (*service.Server, error)

Select chooses a server using round-robin algorithm

func (*RoundRobin) UpdateHealth

func (rr *RoundRobin) UpdateHealth(server *service.Server, healthy bool)

UpdateHealth is a no-op for round-robin

type WeightedRoundRobin

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

WeightedRoundRobin implements smooth weighted round-robin load balancing

func NewWeightedRoundRobin

func NewWeightedRoundRobin() *WeightedRoundRobin

NewWeightedRoundRobin creates a new weighted round-robin load balancer

func (*WeightedRoundRobin) OnRequestEnd

func (wrr *WeightedRoundRobin) OnRequestEnd(backend *route.NormalizedBackend, server *service.Server)

OnRequestEnd is a no-op for weighted round-robin

func (*WeightedRoundRobin) OnRequestStart

func (wrr *WeightedRoundRobin) OnRequestStart(backend *route.NormalizedBackend, server *service.Server)

OnRequestStart is a no-op for weighted round-robin

func (*WeightedRoundRobin) Select

func (wrr *WeightedRoundRobin) Select(req *http.Request, backend *route.NormalizedBackend) (*service.Server, error)

Select chooses a server using weighted round-robin algorithm

func (*WeightedRoundRobin) UpdateHealth

func (wrr *WeightedRoundRobin) UpdateHealth(server *service.Server, healthy bool)

UpdateHealth resets weights when health status changes

Jump to

Keyboard shortcuts

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