Documentation
¶
Overview ¶
Package selector provides pluggable load-balancing over a set of nodes, with optional result feedback via DoneFunc so strategies can adapt to per-node health (strategy pattern + feedback loop).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterSelector ¶
RegisterSelector registers a selector Factory under name. Implementations call this from init().
func Registered ¶
Registered reports whether a selector strategy is registered under name.
Types ¶
type DoneFunc ¶
DoneFunc is called after a call completes so the selector can feed the result back into its decision making.
type Node ¶
type Node interface {
// Address is the host:port to connect to.
Address() string
// Scheme is the transport scheme, e.g. "grpc" or "http".
Scheme() string
// ServiceName is the logical service name.
ServiceName() string
// Weight is the node's static weight (>=0).
Weight() int
// Metadata carries arbitrary tags.
Metadata() map[string]string
}
Node abstracts a selectable instance.
type Selector ¶
type Selector interface {
// Select returns the chosen node and a DoneFunc to report the call result.
// It returns an error when no node is available.
Select(ctx context.Context, nodes []Node) (Node, DoneFunc, error)
}
Selector selects a node from the candidate set.
func GetSelector ¶
GetSelector returns a new Selector by name.
func WithCircuitBreaker ¶
func WithCircuitBreaker(sel Selector, opts ...resilience.BreakerOption) Selector
WithCircuitBreaker decorates sel with per-node circuit breaking. Selection skips nodes whose breaker has tripped, and each call's result is fed back into that node's breaker via the DoneFunc, so a failing node is gradually cut off from selection and can recover through the breaker's force-pass probe. It composes with any strategy, including p2c's EWMA feedback.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package p2c implements a power-of-two-choices selector with time-decayed EWMA latency and success tracking, inspired by go-zero's p2c_ewma.
|
Package p2c implements a power-of-two-choices selector with time-decayed EWMA latency and success tracking, inspired by go-zero's p2c_ewma. |
|
Package random provides a uniformly random selector.
|
Package random provides a uniformly random selector. |
|
Package roundrobin provides a round-robin selector.
|
Package roundrobin provides a round-robin selector. |
|
Package weighted provides a weight-aware random selector.
|
Package weighted provides a weight-aware random selector. |