roundrobin

package
v0.0.0-...-76a1c4c Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

package roundrobin implements dynamic weighted round robin load balancer http handler

package stickysession is a mixin for load balancers that implements layer 7 (http cookie) session affinity

Index

Constants

View Source
const (
	// This is the maximum weight that handler will set for the server
	FSMMaxWeight = 4096
	// Multiplier for the server weight
	FSMGrowFactor = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LBOption

type LBOption func(*RoundRobin) error

LBOption provides options for load balancer

func EnableStickySession

func EnableStickySession(ss *StickySession) LBOption

func ErrorHandler

func ErrorHandler(h utils.ErrorHandler) LBOption

ErrorHandler is a functional argument that sets error handler of the server

type Meter

type Meter interface {
	Rating() float64
	Record(int, time.Duration)
	IsReady() bool
}

Meter measures server peformance and returns it's relative value via rating

type NewMeterFn

type NewMeterFn func() (Meter, error)

type Rebalancer

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

Rebalancer increases weights on servers that perform better than others. It also rolls back to original weights if the servers have changed. It is designed as a wrapper on top of the roundrobin.

func NewRebalancer

func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error)

func (*Rebalancer) RemoveServer

func (rb *Rebalancer) RemoveServer(u *url.URL) error

func (*Rebalancer) ServeHTTP

func (rb *Rebalancer) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Rebalancer) Servers

func (rb *Rebalancer) Servers() []*url.URL

func (*Rebalancer) UpsertServer

func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error

func (*Rebalancer) Wrap

func (rb *Rebalancer) Wrap(next balancerHandler) error

type RebalancerOption

type RebalancerOption func(*Rebalancer) error

RebalancerOption - functional option setter for rebalancer

func RebalancerBackoff

func RebalancerBackoff(d time.Duration) RebalancerOption

func RebalancerClock

func RebalancerClock(clock timetools.TimeProvider) RebalancerOption

func RebalancerErrorHandler

func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption

RebalancerErrorHandler is a functional argument that sets error handler of the server

func RebalancerLogger

func RebalancerLogger(log utils.Logger) RebalancerOption

func RebalancerMeter

func RebalancerMeter(newMeter NewMeterFn) RebalancerOption

func RebalancerStickySession

func RebalancerStickySession(ss *StickySession) RebalancerOption

type RoundRobin

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

func New

func New(next http.Handler, opts ...LBOption) (*RoundRobin, error)

func (*RoundRobin) Next

func (r *RoundRobin) Next() http.Handler

func (*RoundRobin) NextServer

func (r *RoundRobin) NextServer() (*url.URL, error)

func (*RoundRobin) RemoveServer

func (r *RoundRobin) RemoveServer(u *url.URL) error

func (*RoundRobin) ServeHTTP

func (r *RoundRobin) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*RoundRobin) ServerWeight

func (rr *RoundRobin) ServerWeight(u *url.URL) (int, bool)

func (*RoundRobin) Servers

func (rr *RoundRobin) Servers() []*url.URL

func (*RoundRobin) UpsertServer

func (rr *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error

In case if server is already present in the load balancer, returns error

type ServerOption

type ServerOption func(*server) error

ServerOption provides various options for server, e.g. weight

func Weight

func Weight(w int) ServerOption

Weight is an optional functional argument that sets weight of the server

type StickySession

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

func NewStickySession

func NewStickySession(c string) *StickySession

func (*StickySession) GetBackend

func (s *StickySession) GetBackend(req *http.Request, servers []*url.URL) (*url.URL, bool, error)

GetBackend returns the backend URL stored in the sticky cookie, iff the backend is still in the valid list of servers.

func (*StickySession) StickBackend

func (s *StickySession) StickBackend(backend *url.URL, w *http.ResponseWriter)

Jump to

Keyboard shortcuts

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