pub struct WeightedRoundRobin { /* private fields */ }Expand description
Smooth weighted round-robin (Nginx-style).
Each node maintains a running current_weight. On each selection:
- Add each node’s effective weight to its current weight
- Select the node with the highest current weight
- Subtract total weight from the selected node’s current weight
This produces an interleaved sequence that respects relative weights.
State is tracked by a fingerprint of the candidate set (IDs and weights). If the candidate list changes — nodes added/removed/reordered, or a node’s weight changes — the internal state resets and re-converges within a few rounds.
Implementations§
Trait Implementations§
Source§impl Debug for WeightedRoundRobin
impl Debug for WeightedRoundRobin
Source§impl Default for WeightedRoundRobin
impl Default for WeightedRoundRobin
Source§impl<N: Weighted + Node> Strategy<N> for WeightedRoundRobin
impl<N: Weighted + Node> Strategy<N> for WeightedRoundRobin
Source§fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
Pick the next node. Returns
None when candidates is empty or all
candidates are excluded via SelectionContext::exclude.Auto Trait Implementations§
impl !Freeze for WeightedRoundRobin
impl RefUnwindSafe for WeightedRoundRobin
impl Send for WeightedRoundRobin
impl Sync for WeightedRoundRobin
impl Unpin for WeightedRoundRobin
impl UnsafeUnpin for WeightedRoundRobin
impl UnwindSafe for WeightedRoundRobin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more