oxy: github.com/vulcand/oxy/roundrobin Index | Files

package roundrobin

import "github.com/vulcand/oxy/roundrobin"

Package roundrobin implements dynamic weighted round robin load balancer http handler

Index

Package Files

RequestRewriteListener.go rebalancer.go rr.go stickysessions.go

Constants

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

func SetDefaultWeight Uses

func SetDefaultWeight(weight int) error

SetDefaultWeight sets the default server weight

type CookieOptions Uses

type CookieOptions struct {
    HTTPOnly bool
    Secure   bool

    Path    string
    Domain  string
    Expires time.Time

    MaxAge   int
    SameSite http.SameSite
}

CookieOptions has all the options one would like to set on the affinity cookie

type LBOption Uses

type LBOption func(*RoundRobin) error

LBOption provides options for load balancer

func EnableStickySession Uses

func EnableStickySession(stickySession *StickySession) LBOption

EnableStickySession enable sticky session

func ErrorHandler Uses

func ErrorHandler(h utils.ErrorHandler) LBOption

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

func RoundRobinLogger Uses

func RoundRobinLogger(l *log.Logger) LBOption

RoundRobinLogger defines the logger the round robin load balancer will use.

It defaults to logrus.StandardLogger(), the global logger used by logrus.

func RoundRobinRequestRewriteListener Uses

func RoundRobinRequestRewriteListener(rrl RequestRewriteListener) LBOption

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

type Meter Uses

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

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

type NewMeterFn Uses

type NewMeterFn func() (Meter, error)

NewMeterFn type of functions to create new Meter

type Rebalancer Uses

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 Uses

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

NewRebalancer creates a new Rebalancer

func (*Rebalancer) RemoveServer Uses

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

RemoveServer remove a server

func (*Rebalancer) ServeHTTP Uses

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

func (*Rebalancer) Servers Uses

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

Servers gets all servers

func (*Rebalancer) UpsertServer Uses

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

UpsertServer upsert a server

func (*Rebalancer) Wrap Uses

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

Wrap sets the next handler to be called by rebalancer handler.

type RebalancerOption Uses

type RebalancerOption func(*Rebalancer) error

RebalancerOption - functional option setter for rebalancer

func RebalancerBackoff Uses

func RebalancerBackoff(d time.Duration) RebalancerOption

RebalancerBackoff sets a beck off duration

func RebalancerClock Uses

func RebalancerClock(clock timetools.TimeProvider) RebalancerOption

RebalancerClock sets a clock

func RebalancerErrorHandler Uses

func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption

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

func RebalancerLogger Uses

func RebalancerLogger(l *log.Logger) RebalancerOption

RebalancerLogger defines the logger the rebalancer will use.

It defaults to logrus.StandardLogger(), the global logger used by logrus.

func RebalancerMeter Uses

func RebalancerMeter(newMeter NewMeterFn) RebalancerOption

RebalancerMeter sets a Meter builder function

func RebalancerRequestRewriteListener Uses

func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption

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

func RebalancerStickySession Uses

func RebalancerStickySession(stickySession *StickySession) RebalancerOption

RebalancerStickySession sets a sticky session

type RequestRewriteListener Uses

type RequestRewriteListener func(oldReq *http.Request, newReq *http.Request)

RequestRewriteListener function to rewrite request

type RoundRobin Uses

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

RoundRobin implements dynamic weighted round robin load balancer http handler

func New Uses

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

New created a new RoundRobin

func (*RoundRobin) Next Uses

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

Next returns the next handler

func (*RoundRobin) NextServer Uses

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

NextServer gets the next server

func (*RoundRobin) RemoveServer Uses

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

RemoveServer remove a server

func (*RoundRobin) ServeHTTP Uses

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

func (*RoundRobin) ServerWeight Uses

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

ServerWeight gets the server weight

func (*RoundRobin) Servers Uses

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

Servers gets servers URL

func (*RoundRobin) UpsertServer Uses

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

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

type ServerOption Uses

type ServerOption func(*server) error

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

func Weight Uses

func Weight(w int) ServerOption

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

type StickySession Uses

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

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

func NewStickySession Uses

func NewStickySession(cookieName string) *StickySession

NewStickySession creates a new StickySession

func NewStickySessionWithOptions Uses

func NewStickySessionWithOptions(cookieName string, options CookieOptions) *StickySession

NewStickySessionWithOptions creates a new StickySession whilst allowing for options to shape its affinity cookie such as "httpOnly" or "secure"

func (*StickySession) GetBackend Uses

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 Uses

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

StickBackend creates and sets the cookie

Package roundrobin imports 9 packages (graph) and is imported by 94 packages. Updated 2020-03-21. Refresh now. Tools for package owners.