v3

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnCreate = errors.New("connection create failed")

	ErrUnknownLocation = errors.New("unknown location")
	ErrNoSuchID        = errors.New("no such id")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// LocationPreference defines location processing sequence.
	// See GetConn().
	LocationPreference []string

	// ConnsPerEndpoint specifies how many individual connections will be
	// spawned during Add() call.
	ConnsPerEndpoint int

	// IgnoreLocations explicitly sets to ignore LocationPreference and
	// use common default location for all endpoints.
	// If LocationPreference is empty, default location is used regardless
	// of this flag's value.
	IgnoreLocations bool
}

Config provides initial params for Grid.

type Grid

type Grid[PT connection[T], T any] struct {
	// contains filtered or unexported fields
}

Grid is fixed-level load balancer that is specifically balances between connections grouped by locations.

func NewGrid

func NewGrid[PT connection[T], T any](cfg Config) *Grid[PT, T]

NewGrid creates new grid load balancer.

func (*Grid[PT, T]) Add

func (g *Grid[PT, T]) Add(location string, creatF createFunc[PT, T]) error

Add creates connections in specified location.

func (*Grid[PT, T]) Delete

func (g *Grid[PT, T]) Delete(location string, id uint64) error

Delete deletes connections from location. It uses linear search within location to find all matching connections. 'Slots' from deleted connections can be reused later by Add().

func (*Grid[PT, T]) GetConn

func (g *Grid[PT, T]) GetConn() PT

GetConn selects balanced connection based on available locations and alive connections. - It will always return connections from first location in LocationPreference list. - If there's no alive connections in current location, next location from the list is used (and so on). - If end of list is reached and there's still alive endpoints from locations that are not in this list, GetConn() will select them in no particular location-order. - If IgnoreLocations is set, it uses only default location.

Within one location connections are selected using round-robin approach.

Jump to

Keyboard shortcuts

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