Documentation
¶
Overview ¶
Package balancer provides load balancing of network connections per different strategies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fastest ¶
func Fastest(dialers []*dialer) dialerHeap
Fastest strategy always pick the dialer with lowest recent average connect time
func QualityFirst ¶
func QualityFirst(dialers []*dialer) dialerHeap
QualityFirst strategy behaves the same as Fastest strategy when both dialers are good recently, and falls back to Sticky strategy in other cases.
Types ¶
type Balancer ¶
type Balancer struct {
// contains filtered or unexported fields
}
Balancer balances connections among multiple Dialers.
func (*Balancer) Close ¶
func (b *Balancer) Close()
Close closes this Balancer, stopping all background processing. You must call Close to avoid leaking goroutines.
func (*Balancer) Dial ¶
Dial dials (network, addr) using one of the currently active configured Dialers. The Dialer to choose depends on the Strategy when creating the balancer. Only Trusted Dialers are used to dial HTTP hosts.
If a Dialer fails to connect, Dial will keep trying at most 3 times until it either manages to connect, or runs out of dialers in which case it returns an error.
type Dialer ¶
type Dialer struct { // Label: optional label with which to tag this dialer for debug logging. Label string // DialFN: this function dials the given network, addr. DialFN func(network, addr string) (net.Conn, error) // OnClose: (optional) callback for when this dialer is stopped. OnClose func() // Check: - a function that's used to test reachibility metrics // periodically or if the dialer was failed to connect. // It should return true for a successful check. // // Checks are scheduled at exponentially increasing intervals if dialer is // failed. Balancer will also schedule check when required. Check func() bool // Determines whether a dialer can be trusted with unencrypted traffic. Trusted bool // Modifies any HTTP requests made using connections from this dialer. OnRequest func(req *http.Request) }
Dialer captures the configuration for dialing arbitrary addresses.