#pool #async-pool #orm #database

fast_pool

The Fast Pool based on channel

2 releases

new 0.2.1 Nov 16, 2024
0.2.0 Dec 28, 2023
0.1.9 Dec 28, 2023

#50 in Caching

Download history 622/week @ 2024-07-28 600/week @ 2024-08-04 622/week @ 2024-08-11 568/week @ 2024-08-18 469/week @ 2024-08-25 518/week @ 2024-09-01 653/week @ 2024-09-08 445/week @ 2024-09-15 556/week @ 2024-09-22 574/week @ 2024-09-29 765/week @ 2024-10-06 555/week @ 2024-10-13 782/week @ 2024-10-20 496/week @ 2024-10-27 478/week @ 2024-11-03 332/week @ 2024-11-10

2,144 downloads per month
Used in 22 crates (via rbdc-pool-fast)

Apache-2.0

13KB
210 lines

fast_pool

unsafe forbidden GitHub release

a fast async pool based on channel

  • support get(),get_timeout(),state() methods
  • support atomic max_open(Resize freely)
  • based on flume

way fast_pool?

  • fast get() method performance
//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
fast_pool="0.1"
async-trait = "0.1"
tokio = {version = "1",features = ["time","rt-multi-thread","macros"]}
  • impl trait
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<Self::Connection, Self::Error> {
        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());
}

Dependencies

~2.5–8.5MB
~70K SLoC