pub struct RoundRobin {
pub next_backend: u32,
/* private fields */
}Expand description
Round-robin selection, weighted by weight through smooth weighted round
robin (the nginx ngx_http_upstream_get_peer scheme).
§Equal weights: the cursor
When every candidate carries the same weight — the default, since an unset
weight reads as DEFAULT_WEIGHT — the selection is the historical
cursor over the candidate view: position next_backend % len, then the
cursor advances. The weighted scheme would visit a fixed set in the same
order, but the cursor is what decides how a selection continues once the
set shrinks or grows (a backend backs off, recovers, or is excluded by a
retry), so keeping it for equal weights keeps every such sequence exactly
as it was.
§Unequal weights: smooth weighted round robin
Each backend of the list carries a running current weight. A selection
adds every candidate’s weight to its current, picks the candidate with
the largest current (the first in view order on a tie), and subtracts the
sum of the candidates’ weights from the winner’s. Over a fixed set, a
backend of weight w is picked exactly w times in every Σw selections,
and the picks interleave rather than bunch: weights 5, 1, 1 yield
a a b a c a a, not a a a a a b c.
The weight is backend_weight’s, clamped to at least 1, as for
Rendezvous and Maglev: a 0 or negative weight leaves a backend in
the rotation at the smallest share, never out of it.
The running weights are indexed by list position. Self::rebuild, which
the backend list calls whenever a backend is added, removed or reweighted,
resets them, off the datapath; a backend that is not a candidate of one
selection keeps its running weight for the next.
Telling the two cases apart reads every candidate’s weight on each selection. That is deliberate: the candidates are the eligible subset of the list, which changes with health and retries, so a flag cached on the list could not say whether THIS subset is uniform.
Fields§
§next_backend: u32Implementations§
Source§impl RoundRobin
impl RoundRobin
Trait Implementations§
Source§impl Debug for RoundRobin
impl Debug for RoundRobin
Source§impl Default for RoundRobin
impl Default for RoundRobin
Source§impl LoadBalancingAlgorithm for RoundRobin
impl LoadBalancingAlgorithm for RoundRobin
Source§fn next_available_backend(
&mut self,
_key: Option<u64>,
backends: Candidates<'_>,
) -> Option<Rc<RefCell<Backend>>>
fn next_available_backend( &mut self, _key: Option<u64>, backends: Candidates<'_>, ) -> Option<Rc<RefCell<Backend>>>
candidates. Read moreSource§fn rebuild(&mut self, backends: &[Rc<RefCell<Backend>>])
fn rebuild(&mut self, backends: &[Rc<RefCell<Backend>>])
Maglev rebuilds
its table, and RoundRobin (with the round-robin fallback of
Rendezvous and Maglev) resets its running weights.