balancer

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package balancer implements tiered pooling behavior across resolved backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

A Backend creates connections to one specific backend (e.g. a TCP connection to a specific IP address).

func (*Backend) Addr added in v0.1.3

func (b *Backend) Addr() net.Addr

Addr returns the Backend address.

func (*Backend) AssignTier added in v0.1.4

func (b *Backend) AssignTier(latency time.Duration, tier int)

AssignTier (re-)assigns a Backend to a tier based on a latency metric.

func (*Backend) Disable added in v0.1.4

func (b *Backend) Disable()

Disable takes the Backend out of rotation for the configured duration.

func (*Backend) ForcePromotionAfter added in v0.1.2

func (b *Backend) ForcePromotionAfter() time.Duration

ForcePromotionAfter indicates that clients should be forcefully disconnected from this backend if a better choice is available.

func (*Backend) MarshalYAML added in v0.1.2

func (b *Backend) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler interfare and provides a diagnostic view of the Backend.

func (*Backend) MaxLoad added in v0.1.3

func (b *Backend) MaxLoad() int

MaxLoad implements pool.Entry and reflects the number of concurrent calls to Dial().

func (*Backend) String

func (b *Backend) String() string

func (*Backend) Tier

func (b *Backend) Tier() int

Tier implements pool.Entry and reflects the overall priority of the Backend.

type BackendToken added in v0.1.3

type BackendToken struct {
	*pool.Token
	// contains filtered or unexported fields
}

BackendToken is a typesafe wrapper around pool.Token.

func (*BackendToken) Balancer added in v0.1.3

func (t *BackendToken) Balancer() *Balancer

Balancer returns the owner.

func (*BackendToken) Entry added in v0.1.3

func (t *BackendToken) Entry() *Backend

Entry provides type safety around Token.Entry.

type Balancer

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

A Balancer implements pooling behavior across resolved backends.

func (*Balancer) Config

func (b *Balancer) Config() *config.BackendPool

Config returns the currently-active configuration.

func (*Balancer) Configure

func (b *Balancer) Configure(ctx context.Context, cfg config.BackendPool, tolerateErrors bool) error

Configure will initialize or update the pool configuration and attempt to resolve the targets.

func (*Balancer) IsOverloaded added in v0.1.3

func (b *Balancer) IsOverloaded(backend *Backend) bool

IsOverloaded returns true if the given backend should be considered to be in an overload situation (e.g. when draining).

func (*Balancer) MarshalYAML added in v0.1.2

func (b *Balancer) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler and provides a diagnostic view of the Balancer.

func (*Balancer) Pick

func (b *Balancer) Pick() *BackendToken

Pick returns the next best choice from the pool or nil if one is not available.

func (*Balancer) Rebalance added in v0.1.2

func (b *Balancer) Rebalance(context.Context)

Rebalance will rebalance the underlying pool by assigning backends to latency buckets.

func (*Balancer) String

func (b *Balancer) String() string

func (*Balancer) Wait added in v0.1.2

func (b *Balancer) Wait(ctx context.Context) (*BackendToken, error)

Wait blocks until a Backend can be returned or the context is canceled.

type Key

type Key int

Key is a typesafe Context key.

const (
	// KeyBackendToken retrieves a *BackendToken from a Context.
	KeyBackendToken Key = iota + 1
)

Jump to

Keyboard shortcuts

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