Help us shape the future of Go! Take the 2026 Go Developer Survey

loadbalance

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: Apache-2.0 Imports: 11 Imported by: 12

Documentation

Index

Constants

View Source
const (
	DefaultRefreshInterval = 5 * time.Second
	DefaultExpireInterval  = 15 * time.Second
)

Variables

View Source
var DefaultLbOpts = Options{
	RefreshInterval: DefaultRefreshInterval,
	ExpireInterval:  DefaultExpireInterval,
}

Functions

This section is empty.

Types

type BalancerFactory

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

func NewBalancerFactory

func NewBalancerFactory(config Config) *BalancerFactory

NewBalancerFactory get or create a balancer with given target. If it has the same key(resolver.Target(target)), we will cache and reuse the Balance.

func (*BalancerFactory) GetInstance

func (b *BalancerFactory) GetInstance(ctx context.Context, req *protocol.Request) (discovery.Instance, error)

type Config

type Config struct {
	Resolver discovery.Resolver
	Balancer Loadbalancer
	LbOpts   Options
}

type Loadbalancer

type Loadbalancer interface {
	// Pick is used to select an instance according to discovery result
	Pick(discovery.Result) discovery.Instance

	// Rebalance is used to refresh the cache of load balance's information
	Rebalance(discovery.Result)

	// Delete is used to delete the cache of load balance's information when it is expired
	Delete(string)

	// Name returns the name of the Loadbalancer.
	Name() string
}

Loadbalancer picks instance for the given service discovery result.

func NewWeightedBalancer

func NewWeightedBalancer() Loadbalancer

NewWeightedBalancer creates a loadbalancer using weighted-random algorithm.

type Options

type Options struct {
	// refresh discovery result timely
	RefreshInterval time.Duration

	// Balancer expire check interval
	// we need remove idle Balancers for resource saving
	ExpireInterval time.Duration
}

Options for LoadBalance option

func (*Options) Check

func (v *Options) Check()

Check checks option's param

Jump to

Keyboard shortcuts

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