balancer

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 3, 2019 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balancer

type Balancer interface {
	Balance([]*balancerpb.Server) []*balancerpb.Server
}

Balancer algorithm interface

func NewLeastBusyBalancer

func NewLeastBusyBalancer() Balancer

NewLeastBusyBalancer returns a balancer which returns all known servers in priority order, from least to most busy

func NewRandomBalancer

func NewRandomBalancer() Balancer

NewRandomBalancer returns a balancer which returns all known servers in random order

type BalancerFunc

type BalancerFunc func([]*balancerpb.Server) []*balancerpb.Server

BalancerFunc is a simple balancer function which implements the Balancer interface

func (BalancerFunc) Balance

func (f BalancerFunc) Balance(s []*balancerpb.Server) []*balancerpb.Server

Balance implements Balance

type Config

type Config struct {
	// Balancer chooses can decide whether to provide a complete list,
	// a subset, or a specific list of "picked" servers in a particular order.
	// Default: LeastBusyBalancer
	Balancer Balancer

	Discovery struct {
		// Interval between service discovery checks
		// Default: 5s
		Interval time.Duration
	}
	LoadReport struct {
		// Interval between service load pings
		// Default: 5s
		Interval time.Duration
		// MaxFailures allows up to this number of failures for backend
		// before removing it from set of backends for service.
		// Negative or zero value ignores failures completely.
		// Default: 3
		MaxFailures int
	}
}

Config options

type Discovery

type Discovery interface {
	// Resolve accepts a target string and returns a list of addresses
	Resolve(target string) ([]string, error)
}

Discovery describes a service discovery interface

type Server

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

Server is a gRPC server

func New

func New(discovery Discovery, config *Config) *Server

New creates a new Server instance with a given resolver

func (*Server) GetServers

func (b *Server) GetServers(target string) ([]*balancerpb.Server, error)

GetServers retrieves all known servers for a target service

func (*Server) Reset

func (b *Server) Reset()

Reset resets services cache

func (*Server) Servers

Servers implements RPC server

Jump to

Keyboard shortcuts

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