Expand description
Load balancing strategies and the Strategy trait.
Built-in strategies:
| Strategy | Requires | Algorithm |
|---|---|---|
RoundRobin | — | Sequential cycling |
WeightedRoundRobin | Weighted+Node | Nginx smooth weighted round-robin |
Random | — | Uniform random |
WeightedRandom | Weighted | Proportional random |
LeastLoad | LoadMetric | Pick lowest load_score() |
PowerOfTwoChoices | LoadMetric | Random 2, pick lower load |
ConsistentHash | Node | Virtual-node ring (cached) |
MostAvailable | RateMetric | Pick highest remaining, epsilon tie-break |
Combinators: WithFallback, FallbackChain.
Structs§
- Consistent
Hash - Consistent hashing with virtual nodes.
- Fallback
Chain - Tries each strategy in order until one returns a result.
- Least
Load - Selects the node with the lowest load score.
- Most
Available - Selects the node with the most remaining capacity, with epsilon tie-breaking.
- Power
OfTwo Choices - Power of Two Choices: randomly pick two nodes, select the one with lower load.
- Random
- Uniform random selection.
- Round
Robin - Simple round-robin: cycles through candidates sequentially.
- Selection
Context - Context provided to strategies during node selection.
- Selection
Context Builder - Use builder syntax to set the required parameters and finish by calling the method
Self::build(). - Weighted
Random - Weighted random selection. Nodes with higher weight are proportionally more likely.
- Weighted
Round Robin - Smooth weighted round-robin (Nginx-style).
- With
Fallback - Tries the primary strategy first, falls back to secondary if primary returns
None.
Traits§
- Strategy
- A load balancing strategy that selects a node from a list of candidates.