pub struct LeastUsedStrategy;Expand description
Selects the healthy proxy with the fewest total requests.
Ties are broken by position (the first minimum in the slice wins), giving stable and predictable behaviour.
Runs in O(n) over the healthy candidate slice; suitable for pools of up to ~10,000 proxies.
§Example
use stygian_proxy::strategy::{LeastUsedStrategy, RotationStrategy, ProxyCandidate};
use stygian_proxy::types::ProxyMetrics;
use std::sync::{Arc, atomic::Ordering};
use uuid::Uuid;
let strategy = LeastUsedStrategy;
let busy = Arc::new(ProxyMetrics::default());
busy.requests_total.store(100, Ordering::Relaxed);
let idle = Arc::new(ProxyMetrics::default());
let candidates = vec![
ProxyCandidate { id: Uuid::from_u128(1), weight: 1, metrics: busy, healthy: true },
ProxyCandidate { id: Uuid::from_u128(2), weight: 1, metrics: idle, healthy: true },
];
let chosen = strategy.select(&candidates).await.unwrap();
assert_eq!(chosen.id, Uuid::from_u128(2), "should pick the idle proxy");Trait Implementations§
Source§impl Clone for LeastUsedStrategy
impl Clone for LeastUsedStrategy
Source§fn clone(&self) -> LeastUsedStrategy
fn clone(&self) -> LeastUsedStrategy
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LeastUsedStrategy
impl Debug for LeastUsedStrategy
Source§impl Default for LeastUsedStrategy
impl Default for LeastUsedStrategy
Source§fn default() -> LeastUsedStrategy
fn default() -> LeastUsedStrategy
Returns the “default value” for a type. Read more
Source§impl RotationStrategy for LeastUsedStrategy
impl RotationStrategy for LeastUsedStrategy
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 moreimpl Copy for LeastUsedStrategy
Auto Trait Implementations§
impl Freeze for LeastUsedStrategy
impl RefUnwindSafe for LeastUsedStrategy
impl Send for LeastUsedStrategy
impl Sync for LeastUsedStrategy
impl Unpin for LeastUsedStrategy
impl UnsafeUnpin for LeastUsedStrategy
impl UnwindSafe for LeastUsedStrategy
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