loadbalance

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: Apache-2.0 Imports: 12 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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
	// contains filtered or unexported fields
}

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 KeyFunc

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

KeyFunc should returns 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 NewWeightedBalancer

func NewWeightedBalancer() Loadbalancer

NewWeightedBalancer 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 SynthesizedLoadbalancer

type SynthesizedLoadbalancer struct {
	GetPickerFunc func(discovery.Result) Picker
	NameFunc      func() string
}

SynthesizedLoadbalancer synthesizes a loadbalancer using a GetPickerFunc function.

func (*SynthesizedLoadbalancer) GetPicker

func (slb *SynthesizedLoadbalancer) GetPicker(entry discovery.Result) Picker

GetPicker implements the Loadbalancer interface.

func (*SynthesizedLoadbalancer) Name

func (slb *SynthesizedLoadbalancer) Name() string

Name implements the Loadbalancer interface.

type SynthesizedPicker

type SynthesizedPicker struct {
	NextFunc func(ctx context.Context, request interface{}) discovery.Instance
}

SynthesizedPicker synthesizes a picker using a next function.

func (*SynthesizedPicker) Next

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

Next implements the Picker interface.

Directories

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

Jump to

Keyboard shortcuts

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