Crates.io | tub |
lib.rs | tub |
version | 0.3.7 |
source | src |
created_at | 2023-03-12 19:13:18.691958 |
updated_at | 2023-03-31 04:30:59.512607 |
description | Async Pool |
homepage | https://github.com/wcygan/tub |
repository | https://github.com/wcygan/tub |
max_upload_size | |
id | 808228 |
size | 22,277 |
A blazingly fast object pool for Rust.
Values are retrieved from the pool asynchronously. When the retrieved value goes out of scope, the value is returned to the pool.
Read about the public API: docs.rs/tub
Read about the design: wcygan.io/post/pools
To use Tub, add this to your Cargo.toml:
[dependencies]
tub = "0.3.7"
Then create and use a pool like so:
use tub::Pool;
#[tokio::main]
async fn main() {
// Create a pool
let pool: Pool<Box> = (0..10)
.map(|_| Box { value: 123 })
.into();
// Get a value from the pool
let mut box1 = pool.acquire().await;
// Use the value
box1.foo();
// Modify the value
*box1 = Box { value: 456 };
// Return the value to the pool
drop(box1);
}
struct Box {
value: u32
}
impl Box {
fn foo(&mut self) { }
}
In the "Pools" blog post I benchmarked Tub against other object pools in Rust.
The benchmarks help us understand how efficient the underlying mechanisms for concurrency control, object storage, and object reuse are.
The results are as follows:
The following benchmarks compare the performance of different pools under different amounts of load:
The following benchmarks compare the performance of running 100,000 acquire & release operations across tasks.