Skip to main content

Module strategy

Module strategy 

Source
Expand description

Load balancing strategies and the Strategy trait.

Built-in strategies:

StrategyRequiresAlgorithm
RoundRobinSequential cycling
WeightedRoundRobinWeighted+NodeNginx smooth weighted round-robin
RandomUniform random
WeightedRandomWeightedProportional random
LeastLoadLoadMetricPick lowest load_score()
PowerOfTwoChoicesLoadMetricRandom 2, pick lower load
ConsistentHashNodeVirtual-node ring (cached)
MostAvailableRateMetricPick highest remaining, epsilon tie-break

Combinators: WithFallback, FallbackChain.

Structs§

ConsistentHash
Consistent hashing with virtual nodes.
FallbackChain
Tries each strategy in order until one returns a result.
LeastLoad
Selects the node with the lowest load score.
MostAvailable
Selects the node with the most remaining capacity, with epsilon tie-breaking.
PowerOfTwoChoices
Power of Two Choices: randomly pick two nodes, select the one with lower load.
Random
Uniform random selection.
RoundRobin
Simple round-robin: cycles through candidates sequentially.
SelectionContext
Context provided to strategies during node selection.
SelectionContextBuilder
Use builder syntax to set the required parameters and finish by calling the method Self::build().
WeightedRandom
Weighted random selection. Nodes with higher weight are proportionally more likely.
WeightedRoundRobin
Smooth weighted round-robin (Nginx-style).
WithFallback
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.