lb

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package lb implements the client-side load balancer pattern. When combined with a service discovery system of record, it enables a more decentralized architecture, removing the need for separate load balancers like HAProxy.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoEndpoints = errors.New("no endpoints available")

ErrNoEndpoints is returned when no qualifying endpoints are available.

Functions

func Retry

func Retry(max int, timeout time.Duration, b Balancer) endpoint.Endpoint

Retry wraps a service load balancer and returns an endpoint oriented load balancer for the specified service method. Requests to the endpoint will be automatically load balanced via the load balancer. Requests that return errors will be retried until they succeed, up to max times, or until the timeout is elapsed, whichever comes first.

func RetryWithCallback added in v0.3.0

func RetryWithCallback(timeout time.Duration, b Balancer, cb Callback) endpoint.Endpoint

RetryWithCallback wraps a service load balancer and returns an endpoint oriented load balancer for the specified service method. Requests to the endpoint will be automatically load balanced via the load balancer. Requests that return errors will be retried until they succeed, up to max times, until the callback returns false, or until the timeout is elapsed, whichever comes first.

Types

type Balancer

type Balancer interface {
	Endpoint() (endpoint.Endpoint, error)
}

Balancer yields endpoints according to some heuristic.

func NewRandom

func NewRandom(s sd.Endpointer, seed int64) Balancer

NewRandom returns a load balancer that selects services randomly.

func NewRoundRobin

func NewRoundRobin(s sd.Endpointer) Balancer

NewRoundRobin returns a load balancer that returns services in sequence.

type Callback added in v0.3.0

type Callback func(n int, received error) (keepTrying bool, replacement error)

Callback is a function that is given the current attempt count and the error received from the underlying endpoint. It should return whether the Retry function should continue trying to get a working endpoint, and a custom error if desired. The error message may be nil, but a true/false is always expected. In all cases, if the replacement error is supplied, the received error will be replaced in the calling context.

type RetryError added in v0.3.0

type RetryError struct {
	RawErrors []error // all errors encountered from endpoints directly
	Final     error   // the final, terminating error
}

RetryError is an error wrapper that is used by the retry mechanism. All errors returned by the retry mechanism via its endpoint will be RetryErrors.

func (RetryError) Error added in v0.3.0

func (e RetryError) Error() string

Jump to

Keyboard shortcuts

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