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
- type LBOption
- type Meter
- type NewMeterFn
- type Rebalancer
- func (rb *Rebalancer) RemoveServer(u *url.URL) error
- func (rb *Rebalancer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (rb *Rebalancer) Servers() []*url.URL
- func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error
- func (rb *Rebalancer) Wrap(next balancerHandler) error
- type RebalancerOption
- func RebalancerBackoff(d time.Duration) RebalancerOption
- func RebalancerClock(clock timetools.TimeProvider) RebalancerOption
- func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption
- func RebalancerLogger(log utils.Logger) RebalancerOption
- func RebalancerMeter(newMeter NewMeterFn) RebalancerOption
- func RebalancerStickySession(ss *StickySession) RebalancerOption
- type RoundRobin
- func (r *RoundRobin) Next() http.Handler
- func (r *RoundRobin) NextServer() (*url.URL, error)
- func (r *RoundRobin) RemoveServer(u *url.URL) error
- func (r *RoundRobin) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (rr *RoundRobin) ServerWeight(u *url.URL) (int, bool)
- func (rr *RoundRobin) Servers() []*url.URL
- func (rr *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error
- type ServerOption
- type StickySession
Constants ¶
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 NewMeterFn ¶
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 (*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 ¶
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)