Skip to main content

LoadBalancingAlgorithm

Trait LoadBalancingAlgorithm 

Source
pub trait LoadBalancingAlgorithm: Debug {
    // Required method
    fn next_available_backend(
        &mut self,
        key: Option<u64>,
        candidates: Candidates<'_>,
    ) -> Option<Rc<RefCell<Backend>>>;

    // Provided method
    fn rebuild(&mut self, _backends: &[Rc<RefCell<Backend>>]) { ... }
}

Required Methods§

Source

fn next_available_backend( &mut self, key: Option<u64>, candidates: Candidates<'_>, ) -> Option<Rc<RefCell<Backend>>>

Select the next backend among candidates.

key carries an optional affinity hash: the UDP affinity key, or the client key of an HTTP, HTTPS or TCP request (affinity_key_from_ip, affinity_key_from_value). The stateless/round-robin policies ignore it; the consistent-hashing policies (Rendezvous, Maglev) use it to pin a key to a backend. Passing None preserves the historical, key-agnostic behavior.

A policy reads the candidates through the borrowed Candidates view and clones the Rc of the one backend it returns, nothing else, so a selection allocates nothing.

Provided Methods§

Source

fn rebuild(&mut self, _backends: &[Rc<RefCell<Backend>>])

Called by the control plane when the live backend set for a cluster changes, so table-based policies (Maglev) can recompute their lookup table off the datapath. The default is a no-op; Maglev rebuilds its table, and RoundRobin (with the round-robin fallback of Rendezvous and Maglev) resets its running weights.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§