pub struct LoadBalancer { /* private fields */ }Expand description
A weighted round-robin load balancer over an UpstreamPool.
Selection is lock-free and safe to call concurrently from multiple request handlers. The balancer never modifies backend health state; it only reads it.
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(pool: UpstreamPool) -> Self
pub fn new(pool: UpstreamPool) -> Self
Creates a new round-robin balancer from the given upstream pool.
Builds a virtual slot table where each backend occupies a number
of consecutive slots equal to its weight. For example, given
backends [A(w=3), B(w=1)], the slot table is [0, 0, 0, 1].
Sourcepub fn next(&self) -> Result<UpstreamState>
pub fn next(&self) -> Result<UpstreamState>
Selects the next healthy upstream backend.
Advances the internal counter and walks through the slot table
until a healthy backend is found. If no healthy backend exists
after a full rotation, returns ProxyError::NoHealthyUpstream.
Sourcepub fn pool(&self) -> &UpstreamPool
pub fn pool(&self) -> &UpstreamPool
Returns a reference to the underlying upstream pool.
Trait Implementations§
Source§impl Clone for LoadBalancer
impl Clone for LoadBalancer
Source§fn clone(&self) -> LoadBalancer
fn clone(&self) -> LoadBalancer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LoadBalancer
impl RefUnwindSafe for LoadBalancer
impl Send for LoadBalancer
impl Sync for LoadBalancer
impl Unpin for LoadBalancer
impl UnwindSafe for LoadBalancer
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