Documentation ¶
Overview ¶
Package least implements a loadbalance.Selector that selects hosts using a weighted least connection algorithm. Weights are computed by multiplying the total number of requests made by the number of inflight requests. The host whose weight is the least is chosen.
This algorithm is more expensive than others because it must manage a priority queue and lookup table. But it does have more potential to avoid slow hosts while spreading load evenly across healthy hosts. Client-side load balancing can only track its own requests. Hosts may be under load from other clients.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SelectFrom ¶
func SelectFrom(hosts ...string) loadbalance.Selector
SelectFrom returns a loadbalance.Selector that selects hosts using a weighted least connection algorithm.
func SelectWith ¶
func SelectWith(h Heap) loadbalance.Selector
SelectWith returns a loadbalance.Selector that selects hosts using the provided Heap, which implements a weighted least connection algorithm.
Types ¶
type Heap ¶
type Heap interface { // Dec decrements inflight metric for host. // It should be called after the request has completed. Dec(host string) // Inc increments inflight metric for host. // It should be called after Min() and before the request is sent. Inc(host string) // Len returns the number of hosts in the heap. Len() int // Min returns the host with the smallest weight (the least busy). Min() (host string) }
Heap is an interface defining operations for a min-heap of hosts. It is used by the least selector to determine which host to route requests. The Min method should return the least-busy host.