Documentation ¶
Index ¶
Constants ¶
View Source
const (
// 默认虚拟结点数
DefaultVirualSpots = 400
)
一致性哈希算法
Variables ¶
View Source
var (
ErrNotExistService = errors.New("service instances are not exist")
)
Functions ¶
This section is empty.
Types ¶
type HashLoadBalancer ¶
type HashLoadBalancer struct { }
一致性哈希负载均衡器
func (*HashLoadBalancer) SelectServiceByKey ¶
func (h *HashLoadBalancer) SelectServiceByKey(services []*InstanceInfo, key string) (*InstanceInfo, error)
根据key选择服务器
type InstanceInfo ¶
服务实例结构体
type LoadBalancer ¶
type LoadBalancer interface { // 选择服务器 SelectService(services []*InstanceInfo) (*InstanceInfo, error) // 根据key选择服务器 SelectServiceByKey(service []*InstanceInfo, key string) (*InstanceInfo, error) }
负载均衡器
type RandomLoadBalancer ¶
type RandomLoadBalancer struct { }
随机负载均衡器
func (*RandomLoadBalancer) SelectService ¶
func (r *RandomLoadBalancer) SelectService(services []*InstanceInfo) (*InstanceInfo, error)
选择服务器
type WeightRoundRobinLoadBalancer ¶
type WeightRoundRobinLoadBalancer struct { }
权重平滑负载均衡器
func (*WeightRoundRobinLoadBalancer) SelectService ¶
func (w *WeightRoundRobinLoadBalancer) SelectService(services []*InstanceInfo) (*InstanceInfo, error)
选择服务器 每次当请求到来,选取服务实例时,该策略会遍历服务实例队列中的所有服务实例。 对于每个服务实例,让它的CurWeight 值加上 Weight 值;同时累加所有服务实例的Weight 值,将其保存为Total。 遍历完所有服务实例之后,如果某个服务实例的CurWeight最大,就选择这个服务实例处理本次请求,最后把该服务实例的 CurWeight 减去 Total 值
Click to show internal directories.
Click to hide internal directories.