Documentation ¶
Index ¶
- Constants
- Variables
- type Balancer
- func Build(algorithm string, nodes []string) (Balancer, error)
- func NewBounded(nodes []string) Balancer
- func NewConsistentHash(nodes []string) Balancer
- func NewIPHash(nodes []string) Balancer
- func NewLastLoad(hosts []string) Balancer
- func NewP2C(nodes []string) Balancer
- func NewRandom(nodes []string) Balancer
- func NewRoundRobin(nodes []string) Balancer
- type BaseBalancer
- type Bounded
- type Consistent
- type Factory
- type IPHash
- type LeastLoad
- type P2C
- type Random
- type RoundRobin
Constants ¶
View Source
const Salt = "%#!"
Variables ¶
View Source
var ( NodeHostErr = errors.New("no host") AlgorithmNotSupportedError = errors.New("algorithm not supported") )
View Source
var ( P2CBalancer = "p2c" // p2c 的全称是 power of two choices 负载均衡算法,原理是从两个节点中选择负载较小的节点作为服务端 IPHashBalancer = "ip_hash" // ip_hash 的全称是 ip hash 负载均衡算法,原理是根据客户端的 IP 地址进行哈希计算,将请求分配给固定的一台服务器 ConsistentHashBalancer = "consistent_hash" // consistent_hash 的全称是 consistent hash 负载均衡算法,原理是根据请求的 key 进行哈希计算,将请求分配给哈希环上最近的一台服务器 RandomBalancer = "random" // random 的全称是 random 负载均衡算法,原理是随机选择一台服务器作为服务端 RoundRobinBalancer = "round_robin" // round_robin 的全称是 round robin 负载均衡算法,原理是按照节点列表的顺序依次选择一台服务器作为服务端 LeastLoadBalancer = "least_load" // least_load 的全称是 least load 负载均衡算法,原理是选择负载最小的节点作为服务端 BoundedBalancer = "bounded" // bounded 的全称是 bounded 负载均衡算法,原理是限制服务器的最大并发连接数,防止服务器过载 )
Functions ¶
This section is empty.
Types ¶
type Balancer ¶
type Balancer interface { // Add 添加一个节点 Add(string) // Remove 移除一个节点 Remove(string) // Balance 负载均衡 Balance(string) (string, error) // Inc 增加一个节点的权重 Inc(string) // Done 一个节点完成了一次请求 Done(string) }
Balancer 是一个负载均衡器的接口
func NewConsistentHash ¶
NewConsistentHash 创建一个一致性哈希的负载均衡器
type BaseBalancer ¶
BaseBalancer 是一个负载均衡器的基础实现
type Bounded ¶
type Bounded struct {
// contains filtered or unexported fields
}
type Consistent ¶
type Consistent struct { BaseBalancer // contains filtered or unexported fields }
type IPHash ¶
type IPHash struct {
BaseBalancer
}
IPHash will choose a host based on the client's IP address
type Random ¶
type Random struct { BaseBalancer // contains filtered or unexported fields }
type RoundRobin ¶
type RoundRobin struct { BaseBalancer // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.