pub struct LoadBalancer {
pub algorithm: LoadBalancingAlgorithm,
pub round_robin_index: usize,
pub hash_ring: Vec<(u64, PeerId)>,
pub peer_weights: HashMap<PeerId, f64>,
pub connection_counts: HashMap<PeerId, usize>,
pub response_times: HashMap<PeerId, VecDeque<Duration>>,
pub health_status: HashMap<PeerId, bool>,
}Expand description
Load balancer for distributing connections across peers.
Fields§
§algorithm: LoadBalancingAlgorithmLoad balancing algorithm
round_robin_index: usizeRound-robin state
hash_ring: Vec<(u64, PeerId)>Consistent hashing ring
peer_weights: HashMap<PeerId, f64>Peer weights for weighted algorithms
connection_counts: HashMap<PeerId, usize>Connection counts per peer
response_times: HashMap<PeerId, VecDeque<Duration>>Response time history for least response time algorithm
health_status: HashMap<PeerId, bool>Health check results
Implementations§
Source§impl LoadBalancer
impl LoadBalancer
Sourcepub fn new(algorithm: LoadBalancingAlgorithm) -> Self
pub fn new(algorithm: LoadBalancingAlgorithm) -> Self
Create new load balancer
Sourcepub fn select_peer(
&mut self,
available_peers: &[LibP2PPeerId],
) -> Option<LibP2PPeerId>
pub fn select_peer( &mut self, available_peers: &[LibP2PPeerId], ) -> Option<LibP2PPeerId>
Select next peer based on algorithm
Sourcepub fn update_metrics(
&mut self,
peer: LibP2PPeerId,
connections: usize,
response_time: Option<Duration>,
)
pub fn update_metrics( &mut self, peer: LibP2PPeerId, connections: usize, response_time: Option<Duration>, )
Update peer metrics
Trait Implementations§
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more