load_balancer

package
v0.0.0-...-6cf1638 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: MulanPSL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Pick(*http.Request) *Server
}

Balancer 接口定义了所有负载均衡策略都应实现的公共方法

type BaseBalancer

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

type Factory

type Factory struct {
}

func (*Factory) Produce

func (f *Factory) Produce(kind int, servers []Server) Balancer

type IPHashBalancer

type IPHashBalancer struct {
	BaseBalancer
}

IPHashBalancer IP哈希负载均衡

func NewIPHashBalancer

func NewIPHashBalancer(servers []Server) *IPHashBalancer

func (*IPHashBalancer) Pick

func (ihb *IPHashBalancer) Pick(req *http.Request) *Server

type LoadBalancer

type LoadBalancer struct {
	// key:ServiceName val:load_balancer.Balancer
	LoadBalancerMap sync.Map
}
var Handler *LoadBalancer

Handler 各个业务的负载均衡器

func (*LoadBalancer) Get

func (l *LoadBalancer) Get(service *dao.ServiceDetail) (Balancer, error)

func (*LoadBalancer) Update

func (l *LoadBalancer) Update(serviceName string)

type RandomBalancer

type RandomBalancer struct {
	BaseBalancer
}

RandomBalancer 随机负载均衡

func NewRandomBalancer

func NewRandomBalancer(servers []Server) *RandomBalancer

func (*RandomBalancer) Pick

func (rb *RandomBalancer) Pick(_ *http.Request) *Server

type RoundRobinBalancer

type RoundRobinBalancer struct {
	BaseBalancer
	// contains filtered or unexported fields
}

RoundRobinBalancer 轮询负载均衡

func NewRoundRobinBalancer

func NewRoundRobinBalancer(servers []Server) *RoundRobinBalancer

func (*RoundRobinBalancer) Pick

func (rrb *RoundRobinBalancer) Pick(_ *http.Request) *Server

type Server

type Server struct {
	URL    *url.URL
	Weight int // 权重,用于权重负载均衡
}

type WeightedBalancer

type WeightedBalancer struct {
	BaseBalancer
}

WeightedBalancer 权重负载均衡

func NewWeightedBalancer

func NewWeightedBalancer(servers []Server) *WeightedBalancer

func (*WeightedBalancer) Pick

func (wb *WeightedBalancer) Pick(_ *http.Request) *Server

Jump to

Keyboard shortcuts

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