loadbalancer

package
v0.10.69 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package loadbalancer implements predicates and filter which will match for different backends in a round-robin fashion.

First parameter to LBGroup, lbDecide and LBMember defines a group which determines the set of possible routes to match.

lbDecide's second parameter is the number of members in a loadbalancer group.

LBMember's second parameter is 0-based index of the route among the other routes in the same group.

Eskip example:

hello_lb_group: Path("/foo") && LBGroup("hello")
        -> lbDecide("hello", 3)
        -> <loopback>;
hello_1: Path("/foo") && LBMember("hello",0)
        -> "http://127.0.0.1:12345";
hello_2: Path("/foo") && LBMember("hello",1)
        -> "http://127.0.0.1:12346";
hello_3: Path("/foo") && LBMember("hello",2)
        -> "http://127.0.0.1:12347";

Package loadbalancer also implements health checking of pool members for a group of routes, if backend calls are reported to the loadbalancer.

Based on https://landing.google.com/sre/book/chapters/load-balancing-datacenter.html#identifying-bad-tasks-flow-control-and-lame-ducks-bEs0uy we use

Healthy (healthy)

The backend task has initialized correctly and is processing
requests.

Refusing connections (dead)

The backend task is unresponsive. This can happen because the
task is starting up or shutting down, or because the backend is
in an abnormal state (though it would be rare for a backend to
stop listening on its port if it is not shutting down).

Lame duck (unhealthy)

The backend task is listening on its port and can serve, but is
explicitly asking clients to stop sending requests.

Index

Constants

View Source
const (
	DecideFilterName = "lbDecide"
	DecisionHeader   = "X-Load-Balancer-Member"
)
View Source
const (
	GroupPredicateName  = "LBGroup"
	MemberPredicateName = "LBMember"
)

Variables

This section is empty.

Functions

func BalanceRoute

func BalanceRoute(r *eskip.Route, backends []string) []*eskip.Route

BalanceRoute automatically converts a single route to a set of routes load balanced between the provided backend addresses. It takes a route and a set of backend addresses, and returns a set of routes with each backend replaced by one of the provided ones, plus it generates a decision route. It automatically applies the load balancer predicate and the decision filter, and preserves all the other predicates and filters.

func NewDecide

func NewDecide() filters.Spec

NewDecide create a filter specification for the decision route in load balancing scenarios. It expects two arguments: the name of the load balancing group, and the size of the load balancing group.

func NewGroup

func NewGroup() routing.PredicateSpec

NewGroup creates a predicate spec identifying the entry route of a load balanced route group. E.g. eskip: LBGroup("my-group") where the single mandatory string argument is the name of the group, used as a reference in the LB decision filter and the the group member predicates.

Typically, one such route is used in a load balancer setup and it contains the the decision filter (lbDecide("my-group", 4)). It is recommended to generate these routes with the loadbalancer.Balance() function that expects a single route and N backend endpoints as input and returns the loadbalanced set of routes representing the group.

func NewMember

func NewMember() routing.PredicateSpec

NewMember creates a predicate spec identifying a member route of a load balanced route group. E.g. eskip: LBMember("my-group", 2) where the first argument is the name of the group, while the second is the index of the current route.

Typically, these routes are generated with the loadbalancer.Balance() function. See the description of LBGroup(), too.

Types

type HealthcheckPostProcessor

type HealthcheckPostProcessor struct{ *LB }

HealthcheckPostProcessor wraps the LB structure implementing the routing.PostProcessor interface for filtering healthy routes.

func (HealthcheckPostProcessor) Do

Do filters the routes with healthy backends.

type LB

type LB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LB stores state of routes, which were reported dead or unhealthy by other packages, f.e. proxy. Based on reported routes LB starts to do active healthchecks to find if a route becomes haelthy again. Use NewLB() to create an LB

func New

func New(healthcheckInterval time.Duration) *LB

NewLB creates a new LB and starts background jobs for populating backends to check added routes and checking them every healthcheckInterval.

func (*LB) AddHealthcheck

func (lb *LB) AddHealthcheck(backend string)

AddHealthcheck can be used to report unhealthy routes, which loadbalancer will use to do active healthchecking and dataclients can ask the loadbalancer to filter unhealhyt or dead routes.

func (*LB) FilterHealthyMemberRoutes

func (lb *LB) FilterHealthyMemberRoutes(routes []*routing.Route) []*routing.Route

FilterHealthyMemberRoutes can be used by dataclients to filter for routes that have known not healthy backends.

Jump to

Keyboard shortcuts

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