roundrobin

package
v0.0.0-...-8b1022e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

package roundrobin implements dynamic weighted round robin load balancer http handler

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 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

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

Jump to

Keyboard shortcuts

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