| Crates.io | async_wrr_queue |
| lib.rs | async_wrr_queue |
| version | 0.1.3 |
| created_at | 2023-12-18 07:32:42.835383+00 |
| updated_at | 2024-08-21 22:28:45.985847+00 |
| description | [async & high performance] queued weighted round-robin load balance algorithm |
| homepage | https://github.com/dupeiran001/async_wrr_queue_rs |
| repository | https://github.com/dupeiran001/async_wrr_queue_rs |
| max_upload_size | |
| id | 1073151 |
| size | 25,554 |
this is a wrapping of weighted round-robin
schedule algorithm, utilizing atomic operation
and cache queue in order to avoid lock latency or the schedule latency. And we have
used an async RwLock
(feature default or tokio) to overcome the conflict of select instance and
recalculate queue.
more detailed documented WrrQueue | Instance
use async_wrr_queue::*;
#[tokio::main]
async fn main() {
let mut queue = WrrQueue::new();
// insert many
queue.insert_many(vec![("a", 1usize), ("b", 2usize)]).await;
// insert one
queue.insert(("c", 3usize)).await;
queue.insert_many(vec![("d", 5usize), ("e", 2usize)]).await;
// schedule!
let mut result = Vec::new();
for _ in 0..30 {
result.push(queue.select().await.unwrap().data().clone());
}
// expected to be this sequence:
assert_eq!(result, Vec::from_iter( [ "d", "c", "b", "d", "e", "d", "c", "a", "d", "b", "e", "c", "d"].into_iter().cycle().take(30)));
}
default : tokiotokio : async interface, using tokio::sync::RwLock to guarantee best performanceblocking : not compatible with tokio, using std::sync::RwLock for blocking acquire