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
Sourcepub async fn select(&mut self) -> Option<&Instance<T>>
pub async fn select(&mut self) -> Option<&Instance<T>>
return the selected instance, None if instance_list is empty NOTE: select operation used only atomic operation, and can be paralleled
Sourcepub fn clear_instance(&mut self)
pub fn clear_instance(&mut self)
clear instance in the queue
Sourcepub async fn delete_instance(&mut self, instance: Instance<T>) -> bool
pub async fn delete_instance(&mut self, instance: Instance<T>) -> bool
delete certain instance
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for WrrQueue<T>
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