lb

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	// Balance will return an address for a service or an empty
	// string if no nodes are available.
	Balance(service string) (addr string, err merry.Error)
}

Balancer is a load balancer that wraps a service discovery instance to distribute access across the nodes of a service.

func NewLeastN

func NewLeastN(r sd.Resolver, n int) Balancer

NewLeastN returns a Balancer that returns the node with the least connections of `n` randomly chosen nodes

func NewRandom

func NewRandom(res sd.Resolver) Balancer

NewRandom returns a Balancer that randomly selects one of the current nodes supplied by its Resolver

func NewRoundRobin

func NewRoundRobin(r sd.Resolver) Balancer

NewRoundRobin returns a Balancer that implements round robin load balancing

type Cache

type Cache interface {
	// Next returns an addr given a service name and current addrs
	Next(service string, nodes []string) string
}

Cache encapsulates the stateful parts of a load balancer

type CacheBalancer

type CacheBalancer struct {
	Cache    Cache
	Resolver sd.Resolver
}

func (*CacheBalancer) Balance

func (r *CacheBalancer) Balance(service string) (string, merry.Error)

Jump to

Keyboard shortcuts

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