#pool #orm #channel #database

fast_pool

The Fast Pool based on channel

4 releases

new 0.3.6 Apr 29, 2025
0.3.5 Apr 28, 2025
0.2.2 Apr 24, 2025
0.2.1 Nov 16, 2024
0.1.9 Dec 28, 2023

#40 in Caching

Download history 532/week @ 2025-01-13 589/week @ 2025-01-20 232/week @ 2025-01-27 360/week @ 2025-02-03 358/week @ 2025-02-10 346/week @ 2025-02-17 440/week @ 2025-02-24 281/week @ 2025-03-03 385/week @ 2025-03-10 483/week @ 2025-03-17 375/week @ 2025-03-24 297/week @ 2025-03-31 336/week @ 2025-04-07 378/week @ 2025-04-14 1100/week @ 2025-04-21 1004/week @ 2025-04-28

2,868 downloads per month
Used in 26 crates (via rbdc-pool-fast)

Apache-2.0

17KB
330 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 ----
//Time: 14.0994ms ,each:140 ns/op
//QPS: 7086167 QPS/s
  • Implement using only channels
  • no additional threads
  • Support asynchronous/tokio

how to use this?

  • step 1 add toml
fast_pool="0.3"
tokio = {version = "1",features = ["time","rt-multi-thread","macros"]}
  • step 2 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
~66K SLoC