Struct async_wrr_queue::WrrQueue
source · pub struct WrrQueue<T: PartialEq> { /* private fields */ }
Expand description
weighted round robin queue struct
WRR queue, each time new instance is inserted, balance queue need to be recalculated. So minimizing the insert operation can improve performance.
select
method requires only an atomic usize and a Read access to the RwLock.
There should be of no runtime performance issue.
example:
use async_wrr_queue::{WrrQueue, Instance};
use std::num::NonZeroUsize;
let mut queue = WrrQueue::new().insert_many([("data1", 1), ("data2", 2), ("data3", 3)]).await;
queue.insert(Instance::new_with_weight("data4", NonZeroUsize::new(4).unwrap())).await;
let selected1 = queue.select();
let selected2 = queue.select();
let selected3 = queue.select();
Implementations§
source§impl<T: PartialEq> WrrQueue<T>
impl<T: PartialEq> WrrQueue<T>
sourcepub async fn insert(&mut self, instance: impl Into<Instance<T>>) -> bool
pub async fn insert(&mut self, instance: impl Into<Instance<T>>) -> bool
insert a new instance, and re-calculate request queue
sourcepub async fn insert_many<U>(&mut self, instance_list: impl Into<Vec<U>>) -> bool
pub async fn insert_many<U>(&mut self, instance_list: impl Into<Vec<U>>) -> bool
insert a new instance vec, and re-calculate request queue recommended when have multiple instance to be inserted
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for WrrQueue<T>
impl<T> Send for WrrQueue<T>where
T: Send,
impl<T> Sync for WrrQueue<T>where
T: Sync,
impl<T> Unpin for WrrQueue<T>where
T: Unpin,
impl<T> UnwindSafe for WrrQueue<T>where
T: UnwindSafe,
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