https://github.com/rbatis/fast_pool
a fast async pool based on channel
https://github.com/rbatis/fast_pool
Last synced: 3 months ago
JSON representation
a fast async pool based on channel
- Host: GitHub
- URL: https://github.com/rbatis/fast_pool
- Owner: rbatis
- License: apache-2.0
- Created: 2023-12-26T05:42:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-16T06:05:35.000Z (7 months ago)
- Last Synced: 2025-03-01T10:06:43.791Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 52.7 KB
- Stars: 24
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fast_pool
[](https://github.com/rust-secure-code/safety-dance/)
[](https://github.com/rbatis/fast_pool/releases)
a fast async pool based on channel
* support `get()`,`get_timeout()`,`state()` methods
* support atomic max_open(Resize freely)
* based on [flume](https://crates.io/crates/flume)### way fast_pool?
* fast get() method performance
```log
//windows:
//---- bench_pool stdout ----
//use Time: 4.0313ms ,each:40 ns/op
//use QPS: 24749412 QPS/s
//macos:
//---- bench_pool stdout ----
// use Time: 6.373708ms ,each:63 ns/op
// use QPS: 15683710 QPS/s
```### how to use this?
* add toml
```toml
fast_pool="0.1"
async-trait = "0.1"
tokio = {version = "1",features = ["time","rt-multi-thread","macros"]}
```
* impl trait
```rust
use std::ops::{DerefMut};
use std::time::Duration;
use async_trait::async_trait;
use fast_pool::{Manager, Pool};#[derive(Debug)]
pub struct TestManager {}impl Manager for TestManager {
type Connection = String;
type Error = String;async fn connect(&self) -> Result {
Ok("conn".to_string())
}async fn check(&self, conn: &mut Self::Connection) -> Result<(), Self::Error> {
//check should use conn.ping()
if conn == "error" {
return Err(Self::Error::from("error".to_string()));
}
Ok(())
}
}#[tokio::main]
async fn main() {
let p = Pool::new(TestManager {});
println!("status = {}",p.state());
p.set_max_open(10);
println!("status = {}",p.state());let mut conn = p.get().await.unwrap();
println!("conn = {}",conn.deref_mut());
let mut conn = p.get_timeout(Some(Duration::from_secs(1))).await.unwrap();
println!("conn = {}",conn.deref_mut());
}
```