Documentation ¶
Index ¶
- type AliasMethodPicker
- type ConsistentHashOption
- type DummyPicker
- type InterleavedWeightedRoundRobinPicker
- type KeyFunc
- type Loadbalancer
- func NewConsistBalancer(opt ConsistentHashOption) Loadbalancer
- func NewInterleavedWeightedRoundRobinBalancer() Loadbalancer
- func NewWeightedBalancer() Loadbalancer
- func NewWeightedRandomBalancer() Loadbalancer
- func NewWeightedRandomWithAliasMethodBalancer() Loadbalancer
- func NewWeightedRoundRobinBalancer() Loadbalancer
- type Picker
- type Rebalancer
- type RoundRobinPicker
- type WeightedRoundRobinPicker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AliasMethodPicker ¶ added in v0.9.0
type AliasMethodPicker struct {
// contains filtered or unexported fields
}
type ConsistentHashOption ¶
type ConsistentHashOption struct { GetKey KeyFunc // If it is set, replicas will be used when connect to the primary node fails. // This brings extra mem and cpu cost. // If it is not set, error will be returned immediately when connect fails. Replica uint32 // The number of virtual nodes corresponding to each real node // The larger the value, the higher the memory and computational cost, and the more balanced the load // When the number of nodes is large, it can be set smaller; conversely, it can be set larger // The median VirtualFactor * Weight (if Weighted is true) is recommended to be around 1000 // The recommended total number of virtual nodes is within 2000W (it takes 250ms to build once in the 1000W case, but it is theoretically fine to build in the background within 3s) VirtualFactor uint32 // Whether to follow Weight for load balancing // If false, Weight is ignored for each instance, and VirtualFactor virtual nodes are generated for indiscriminate load balancing // if true, Weight() * VirtualFactor virtual nodes are generated for each instance // Note that for instance with weight 0, no virtual nodes will be generated regardless of the VirtualFactor number // It is recommended to set it to true, but be careful to reduce the VirtualFactor appropriately Weighted bool // Deprecated: This implementation will not cache all the keys anymore, ExpireDuration will not take effect // Whether or not to perform expiration processing // The implementation will cache all the keys // If never expired it may cause memory to keep growing and eventually OOM // Setting expiration will result in additional performance overhead // Current implementations scan for deletions every minute, and delete once when the instance changes rebuild // It is recommended to always set the value not less than two minutes ExpireDuration time.Duration }
ConsistentHashOption .
func NewConsistentHashOption ¶
func NewConsistentHashOption(f KeyFunc) ConsistentHashOption
NewConsistentHashOption creates a default ConsistentHashOption.
type DummyPicker ¶
type DummyPicker struct{}
DummyPicker is a picker that always returns nil on Next.
type InterleavedWeightedRoundRobinPicker ¶ added in v0.7.0
type InterleavedWeightedRoundRobinPicker struct {
// contains filtered or unexported fields
}
type KeyFunc ¶
KeyFunc should return a non-empty string that stands for the request within the given context.
type Loadbalancer ¶
Loadbalancer generates pickers for the given service discovery result.
func NewConsistBalancer ¶
func NewConsistBalancer(opt ConsistentHashOption) Loadbalancer
NewConsistBalancer creates a new consist balancer with the given option.
func NewInterleavedWeightedRoundRobinBalancer ¶ added in v0.7.0
func NewInterleavedWeightedRoundRobinBalancer() Loadbalancer
NewInterleavedWeightedRoundRobinBalancer creates a loadbalancer using interleaved-weighted-round-robin algorithm.
func NewWeightedBalancer ¶
func NewWeightedBalancer() Loadbalancer
NewWeightedBalancer creates a loadbalancer using weighted-round-robin algorithm.
func NewWeightedRandomBalancer ¶ added in v0.5.0
func NewWeightedRandomBalancer() Loadbalancer
NewWeightedRandomBalancer creates a loadbalancer using weighted-random algorithm.
func NewWeightedRandomWithAliasMethodBalancer ¶ added in v0.9.0
func NewWeightedRandomWithAliasMethodBalancer() Loadbalancer
NewWeightedRandomWithAliasMethodBalancer creates a loadbalancer using alias-method algorithm.
func NewWeightedRoundRobinBalancer ¶ added in v0.5.0
func NewWeightedRoundRobinBalancer() Loadbalancer
NewWeightedRoundRobinBalancer creates a loadbalancer using weighted-round-robin algorithm.
type Rebalancer ¶
Rebalancer is a kind of Loadbalancer that performs rebalancing when the result of service discovery changes.
type RoundRobinPicker ¶ added in v0.5.0
type RoundRobinPicker struct {
// contains filtered or unexported fields
}
RoundRobinPicker .
type WeightedRoundRobinPicker ¶ added in v0.5.0
type WeightedRoundRobinPicker struct {
// contains filtered or unexported fields
}
WeightedRoundRobinPicker implement smooth weighted round-robin algorithm. Refer from https://github.com/phusion/nginx/commit/27e94984486058d73157038f7950a0a36ecc6e35