Skip to main content

Crate load_balancer

Crate load_balancer 

Source
Expand description

§Load Balancer Library

This library provides a set of generic load balancer implementations for distributing workloads across multiple targets, such as clients, network endpoints, or resources.

§Traits

§LoadBalancer<T>

A generic trait for asynchronous or synchronous load balancing. Implementors provide methods to allocate a resource from the pool.

use std::future::Future;

pub trait LoadBalancer<T>: Send + Sync + Clone + 'static {
    /// Asynchronously allocate a resource.
    fn alloc(&self) -> impl Future<Output = T> + Send;

    /// Attempt to allocate a resource synchronously without awaiting.
    fn try_alloc(&self) -> Option<T>;
}

§FilteredLoadBalancer<T>

A trait for load balancers that support predicate-based filtering. Unlike LoadBalancer, filter methods return (usize, T) — the entry index alongside the value — so callers can identify the allocated entry.

use std::future::Future;

pub trait FilteredLoadBalancer<T>: Send + Sync + Clone + 'static {
    /// Asynchronously allocate an entry that satisfies the given predicate.
    fn alloc_filter(
        &self,
        predicate: impl FnMut((usize, &T)) -> bool,
    ) -> impl Future<Output = (usize, T)> + Send;

    /// Attempt to allocate an entry that satisfies the predicate without awaiting.
    fn try_alloc_filter(
        &self,
        predicate: impl FnMut((usize, &T)) -> bool,
    ) -> Option<(usize, T)>;
}

Re-exports§

pub use anyhow;
pub use dashmap;
pub use reqwest;

Modules§

cooldown
Cooldown-based load balancer with per-entry reuse intervals.
fault_tolerant
Fault-tolerant load balancer with error tracking and auto-disabling.
proxy_pool
Proxy pool with health checking and latency-based sorting.
random
Random selection load balancer.
rate_limit
Fixed-window rate limiter (single + per-key map).
round_robin
Round-robin sequential load balancer.
window
Sliding-window load balancer with per-entry rate limits.

Traits§

FilteredLoadBalancer
A load balancer that supports predicate-based filtering during allocation.
LoadBalancer
A generic load balancer trait for allocating resources from a pool.