Documentation ¶
Overview ¶
Package picker provides functionality for picking a connection. This is used by an httplb.Client to actually select a connection for use with a given request.
This package defines the core interface, Picker, which is used to select a single connection, from multiple connections in a pool.
This package also contains numerous implementations, all in the form of various functions whose names start with "New". Each such function produces pickers that implement a particular picking algorithm, like round-robin, random, or least-loaded.
None of the provided implementations in this package make use of custom metadata (attribute.Values) for an address. But custom Picker implementations could, for example to prefer backends in clusters that are geographically closer, or to implement custom affinity policies, or even to implement weighted selection algorithms in the face of heterogeneous backends (where the name resolution/service discovery system has information about a backend's capacity).
Index ¶
- type Picker
- func ErrorPicker(err error) Picker
- func NewLeastLoadedRandom(prev Picker, allConns conn.Conns) Picker
- func NewLeastLoadedRoundRobin(prev Picker, allConns conn.Conns) Picker
- func NewPowerOfTwo(prev Picker, allConns conn.Conns) Picker
- func NewRandom(_ Picker, allConns conn.Conns) Picker
- func NewRoundRobin(_ Picker, allConns conn.Conns) Picker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Picker ¶
Picker implements connection selection. For a given request, it returns the connection to use. It also returns a callback that, if non-nil, will be invoked when the operation is complete. (This happens when the HTTP response is returned and its body fully consumed or closed.) Such a callback can be used, for example, to track the number of active requests for a least-loaded implementation.
func ErrorPicker ¶
ErrorPicker returns a picker that always fails with the given error.
func NewLeastLoadedRandom ¶
NewLeastLoadedRandom creates pickers that pick the connection with the fewest in-flight requests. When a tie occurs, tied hosts will be picked at random.
func NewLeastLoadedRoundRobin ¶
NewLeastLoadedRoundRobin creates pickers that pick the connection with the fewest in-flight requests. When a tie occurs, tied hosts will be picked in an arbitrary but sequential order.
func NewPowerOfTwo ¶
NewPowerOfTwo creates pickers that select two connections at random and pick the one with fewer requests. This takes advantage of the power of two random choices, which provides substantial benefits over a simple random picker and, unlike the least-loaded policy, doesn't need to maintain a heap.
func NewRoundRobin ¶
NewRoundRobin creates pickers that pick connections in a "round-robin" fashion, that is to say, in sequential order. In order to mitigate the risk of a "thundering herd" scenario, the order of connections is randomized each time the list of hosts changes.