pub struct MostAvailable { /* private fields */ }Expand description
Selects the node with the most remaining capacity, with epsilon tie-breaking.
Scoring: each candidate’s score is its remaining_ratio().
When multiple candidates score within epsilon of the best,
one is chosen randomly to avoid thundering-herd on the single “most available” node.
§Panics
Panics if epsilon is negative or NaN.
§Examples
use loadwise::{Strategy, RateMetric, SelectionContext};
use loadwise::strategy::MostAvailable;
struct Key { remaining: f64 }
impl RateMetric for Key {
fn remaining_ratio(&self) -> f64 { self.remaining }
}
let strategy = MostAvailable::default();
let keys = [Key { remaining: 0.2 }, Key { remaining: 0.8 }, Key { remaining: 0.75 }];
let ctx = SelectionContext::default();
// Picks index 1 or 2 (both within epsilon=0.05 of best 0.8)
let idx = strategy.select(&keys, &ctx).unwrap();
assert!(idx == 1 || idx == 2);Implementations§
Source§impl MostAvailable
impl MostAvailable
Sourcepub fn builder() -> MostAvailableBuilder
pub fn builder() -> MostAvailableBuilder
Create an instance of MostAvailable using the builder syntax
Trait Implementations§
Source§impl Debug for MostAvailable
impl Debug for MostAvailable
Source§impl Default for MostAvailable
impl Default for MostAvailable
Source§impl<N: RateMetric> Strategy<N> for MostAvailable
impl<N: RateMetric> Strategy<N> for MostAvailable
Source§fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
fn select(&self, candidates: &[N], ctx: &SelectionContext) -> Option<usize>
Pick the next node. Returns
None when candidates is empty or all
candidates are excluded via SelectionContext::exclude.Auto Trait Implementations§
impl Freeze for MostAvailable
impl RefUnwindSafe for MostAvailable
impl Send for MostAvailable
impl Sync for MostAvailable
impl Unpin for MostAvailable
impl UnsafeUnpin for MostAvailable
impl UnwindSafe for MostAvailable
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