pub struct RoundRobinStrategy { /* private fields */ }Expand description
Cycles through healthy proxies in order, distributing load evenly.
Uses a lock-free AtomicUsize counter, so no Mutex is needed even
under high concurrency.
§Example
use stygian_proxy::strategy::{RoundRobinStrategy, RotationStrategy, ProxyCandidate};
use stygian_proxy::types::ProxyMetrics;
use std::sync::Arc;
use uuid::Uuid;
let strategy = RoundRobinStrategy::default();
let candidates = vec![
ProxyCandidate { id: Uuid::new_v4(), weight: 1, metrics: Arc::new(ProxyMetrics::default()), healthy: true },
ProxyCandidate { id: Uuid::new_v4(), weight: 1, metrics: Arc::new(ProxyMetrics::default()), healthy: true },
];
let a = strategy.select(&candidates).await.unwrap().id;
let b = strategy.select(&candidates).await.unwrap().id;
assert_ne!(a, b, "round-robin should alternate between two proxies");Trait Implementations§
Source§impl Debug for RoundRobinStrategy
impl Debug for RoundRobinStrategy
Source§impl Default for RoundRobinStrategy
impl Default for RoundRobinStrategy
Source§fn default() -> RoundRobinStrategy
fn default() -> RoundRobinStrategy
Returns the “default value” for a type. Read more
Source§impl RotationStrategy for RoundRobinStrategy
impl RotationStrategy for RoundRobinStrategy
Source§fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn select<'a, 'life0, 'async_trait>(
&'life0 self,
candidates: &'a [ProxyCandidate],
) -> Pin<Box<dyn Future<Output = ProxyResult<&'a ProxyCandidate>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
Select one candidate from
candidates. Read moreAuto Trait Implementations§
impl !Freeze for RoundRobinStrategy
impl RefUnwindSafe for RoundRobinStrategy
impl Send for RoundRobinStrategy
impl Sync for RoundRobinStrategy
impl Unpin for RoundRobinStrategy
impl UnsafeUnpin for RoundRobinStrategy
impl UnwindSafe for RoundRobinStrategy
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