pub struct LoadBalancer { /* private fields */ }Expand description
Top-level load balancer that manages backend groups keyed by service name.
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn register(
&self,
service: &str,
addrs: Vec<SocketAddr>,
strategy: LbStrategy,
)
pub fn register( &self, service: &str, addrs: Vec<SocketAddr>, strategy: LbStrategy, )
Register (or replace) a backend group for service.
Sourcepub fn select(&self, service: &str) -> Option<Arc<Backend>>
pub fn select(&self, service: &str) -> Option<Arc<Backend>>
Select a healthy backend for service, delegating to the group’s
configured strategy.
Sourcepub fn update_backends(&self, service: &str, addrs: Vec<SocketAddr>)
pub fn update_backends(&self, service: &str, addrs: Vec<SocketAddr>)
Update the backend list for service, preserving state for unchanged
addresses.
Sourcepub fn unregister(&self, service: &str)
pub fn unregister(&self, service: &str)
Remove the backend group for service.
Sourcepub fn add_backend(&self, service: &str, addr: SocketAddr)
pub fn add_backend(&self, service: &str, addr: SocketAddr)
Add a single backend to an existing group.
Sourcepub fn remove_backend(&self, service: &str, addr: &SocketAddr)
pub fn remove_backend(&self, service: &str, addr: &SocketAddr)
Remove a single backend from an existing group.
Sourcepub fn backend_count(&self, service: &str) -> usize
pub fn backend_count(&self, service: &str) -> usize
Return the number of backends registered for service, or 0 if
the service is not registered.
Sourcepub fn healthy_count(&self, service: &str) -> usize
pub fn healthy_count(&self, service: &str) -> usize
Return the number of healthy backends for service, or 0 if the
service is not registered.
Sourcepub fn mark_health(&self, service: &str, addr: &SocketAddr, healthy: bool)
pub fn mark_health(&self, service: &str, addr: &SocketAddr, healthy: bool)
Update the health status of a specific backend in a service group.
If healthy is true, marks the backend healthy and resets its failure
counter. Otherwise marks it unhealthy and records a failure.
Sourcepub fn list_service_names(&self) -> Vec<String>
pub fn list_service_names(&self) -> Vec<String>
Return the list of registered service names.
Sourcepub fn group_snapshot(&self, service: &str) -> Option<BackendGroupSnapshot>
pub fn group_snapshot(&self, service: &str) -> Option<BackendGroupSnapshot>
Return a snapshot of a backend group’s state for a given service.
Each entry contains the backend address, health status, active connections, and the group’s strategy.
Sourcepub fn spawn_health_checker(
self: &Arc<Self>,
interval: Duration,
timeout: Duration,
) -> JoinHandle<()>
pub fn spawn_health_checker( self: &Arc<Self>, interval: Duration, timeout: Duration, ) -> JoinHandle<()>
Spawn a background health-check task.
Every interval the task TCP-connects to every backend across all
groups with a per-probe timeout. Concurrency is bounded to at most
64 simultaneous probes via a semaphore.
On success the backend is marked healthy and its failure counter is reset. On failure it is marked unhealthy and the failure counter is incremented.
§Panics
The spawned task panics if the internal concurrency semaphore is unexpectedly closed.