pub struct LoadBalancer {
pub strategy: LoadBalanceStrategy,
pub workers: Vec<WorkerLoad>,
pub round_robin_idx: usize,
}Expand description
Routes incoming requests to registered worker nodes.
Fields§
§strategy: LoadBalanceStrategy§workers: Vec<WorkerLoad>§round_robin_idx: usizeImplementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(strategy: LoadBalanceStrategy) -> Self
pub fn new(strategy: LoadBalanceStrategy) -> Self
Create a load balancer with the chosen strategy and no workers.
Sourcepub fn add_worker(&mut self, w: WorkerLoad)
pub fn add_worker(&mut self, w: WorkerLoad)
Register a worker node.
Sourcepub fn remove_worker(&mut self, id: u64) -> bool
pub fn remove_worker(&mut self, id: u64) -> bool
Deregister a worker by ID. Returns true if found and removed.
Sourcepub fn select_worker(&mut self) -> Option<u64>
pub fn select_worker(&mut self) -> Option<u64>
Select a worker according to the configured strategy.
Returns None when no workers are registered.
Sourcepub fn update_load(&mut self, worker_id: u64, connections: u32, cpu_pct: f64)
pub fn update_load(&mut self, worker_id: u64, connections: u32, cpu_pct: f64)
Update the connection count and CPU usage for a worker.
Auto Trait Implementations§
impl Freeze for LoadBalancer
impl RefUnwindSafe for LoadBalancer
impl Send for LoadBalancer
impl Sync for LoadBalancer
impl Unpin for LoadBalancer
impl UnsafeUnpin 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request