roundrobin

package
v0.8.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2015 License: 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

func ErrorHandler

func ErrorHandler(h utils.ErrorHandler) rrSetter

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

func RebalancerBackoff

func RebalancerBackoff(d time.Duration) rbOptSetter

func RebalancerClock

func RebalancerClock(clock timetools.TimeProvider) rbOptSetter

func RebalancerLogger

func RebalancerLogger(log utils.Logger) rbOptSetter

func RebalancerMeter

func RebalancerMeter(newMeter NewMeterFn) rbOptSetter

func Weight

func Weight(w int) serverSetter

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

Types

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 ...rbOptSetter) (*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 ...serverSetter) error

func (*Rebalancer) Wrap

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

type RoundRobin

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

func New

func New(next http.Handler, opts ...rrSetter) (*RoundRobin, 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 ...serverSetter) error

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

Jump to

Keyboard shortcuts

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