skipper: github.com/zalando/skipper/loadbalancer Index | Files

package loadbalancer

import "github.com/zalando/skipper/loadbalancer"

Package loadbalancer implements load balancer algorithms that are applied by the proxy.

roundRobin Algorithm

The roundRobin algorithm does proxy requests round robin to
backend endpoints. It has a mutex to update the index and will
start at a random index

random Algorithm

The random algorithm does proxy requests to random backend
endpoints.

consistentHash Algorithm

The consistentHash algorithm choose backend endpoints by hashing
client data with hash function fnv.New32. The client data is the
client IP, which will be looked up from X-Forwarded-For header
with remote IP as the fallback.

Eskip example:

r1: * -> <roundRobin, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
r2: * -> <consistentHash, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;
r3: * -> <random, "http://127.0.0.1:9998", "http://127.0.0.1:9997">;

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

Package Files

algorithm.go doc.go healthchecker.go

func NewAlgorithmProvider Uses

func NewAlgorithmProvider() routing.PostProcessor

NewAlgorithmProvider creates a routing.PostProcessor used to initialize the algorithm of load balancing routes.

type HealthcheckPostProcessor Uses

type HealthcheckPostProcessor struct{ *LB }

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

func (HealthcheckPostProcessor) Do Uses

func (hcpp HealthcheckPostProcessor) Do(r []*routing.Route) []*routing.Route

Do filters the routes with healthy backends.

type LB Uses

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 Uses

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 Uses

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 Uses

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.

Package loadbalancer imports 18 packages (graph) and is imported by 10 packages. Updated 2019-04-20. Refresh now. Tools for package owners.