Documentation ¶
Overview ¶
Package tworandomchoices provides a load balancer implementation that picks two peers at random and chooses the one with fewer pending requests.
The Power of Two Choices in Randomized Load Balancing: https://www.eecs.harvard.edu/~michaelm/postscripts/tpds2001.pdf
The Power of Two Random Choices: A Survey of Techniques and Results: https://www.eecs.harvard.edu/~michaelm/postscripts/handbook2001.pdf
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Spec ¶
func Spec() yarpcconfig.PeerListSpec
Spec returns a configuration specification for the "fewest pending requests of two random peers" implementation, making it possible to select the better of two random peer with transports that use outbound peer list configuration (like HTTP).
cfg := yarpcconfig.New() cfg.MustRegisterPeerList(tworandomchoices.Spec())
This enables the random peer list:
outbounds: otherservice: unary: http: url: https://host:port/rpc two-random-choices: peers: - 127.0.0.1:8080 - 127.0.0.1:8081
Types ¶
type Configuration ¶ added in v1.42.0
Configuration describes how to construct a two-random-choices peer list.
type List ¶
type List struct {
*peerlist.List
}
List is a PeerList that rotates which peers are to be selected randomly
type ListOption ¶
type ListOption interface {
// contains filtered or unexported methods
}
ListOption customizes the behavior of a fewest pending of two random peers list.
func Capacity ¶
func Capacity(capacity int) ListOption
Capacity specifies the default capacity of the underlying data structures for this list.
Defaults to 10.
func FailFast ¶ added in v1.42.0
func FailFast() ListOption
FailFast indicates that the peer list should not wait for a peer to become available when choosing a peer.
This option is preferrable when the better failure mode is to retry from the origin, since another proxy instance might already have a connection.
func Source ¶
func Source(source rand.Source) ListOption
Source is a source of randomness for the peer list.