Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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]) Delete ¶
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.