loadbalance

package
v0.9.3-dep2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 41

Documentation

Index

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
}

func (*AliasMethodPicker) Next added in v0.9.0

func (a *AliasMethodPicker) Next(ctx context.Context, request interface{}) discovery.Instance

Next implements the Picker interface.

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

	// 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.

func (*DummyPicker) Next

func (np *DummyPicker) Next(ctx context.Context, request interface{}) (ins discovery.Instance)

Next implements the Picker interface.

type InterleavedWeightedRoundRobinPicker added in v0.7.0

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

func (*InterleavedWeightedRoundRobinPicker) Next added in v0.7.0

func (ip *InterleavedWeightedRoundRobinPicker) Next(ctx context.Context, request interface{}) discovery.Instance

type KeyFunc

type KeyFunc func(ctx context.Context, request interface{}) string

KeyFunc should return a non-empty string that stands for the request within the given context.

type Loadbalancer

type Loadbalancer interface {
	GetPicker(discovery.Result) Picker
	Name() string // unique key
}

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 Picker

type Picker interface {
	Next(ctx context.Context, request interface{}) discovery.Instance
}

Picker picks an instance for next RPC call.

type Rebalancer

type Rebalancer interface {
	Rebalance(discovery.Change)
	Delete(discovery.Change)
}

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 .

func (*RoundRobinPicker) Next added in v0.5.0

func (rp *RoundRobinPicker) Next(ctx context.Context, request interface{}) (ins discovery.Instance)

Next implements the Picker interface.

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

func (*WeightedRoundRobinPicker) Next added in v0.5.0

func (wp *WeightedRoundRobinPicker) Next(ctx context.Context, request interface{}) (ins discovery.Instance)

Next implements the Picker interface.

Directories

Path Synopsis
Package lbcache combine balancer with resolver and cache the resolve result
Package lbcache combine balancer with resolver and cache the resolve result

Jump to

Keyboard shortcuts

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