Expand description

Connection pooling

This module provides utilities to use connection pooling. As we already know, it is far more efficient to maintain a number of live connections to a database and share them across multiple “worker threads”, using a “connection pool” because creating individual connections whenever a worker receives a task is slow while maintaining a connection per worker might be cumbersome to implement.

To provide connection pooling, we use r2d2 for a sync connection pool while we use bb8 to provide an async connection pool.

Sync usage

Example usage for TLS and non-TLS connection pools are given below.

use skytable::pool::{ConnectionManager, Pool, TlsPool};
use skytable::sync::{Connection, TlsConnection};

// non-TLS (TCP pool)
let notls_manager = ConnectionManager::new_notls("127.0.0.1".into(), 2003);
let notls_pool = Pool::builder()
   .max_size(10)
   .build(notls_manager)
   .unwrap();

// TLS pool
let tls_manager = ConnectionManager::new_tls(
    "127.0.0.1".into(), 2003, "cert.pem".into()
);
let notls_pool = TlsPool::builder()
   .max_size(10)
   .build(tls_manager)
   .unwrap();

Async usage

Example usage for TLS and non-TLS connection pools are given below.

use skytable::pool::{ConnectionManager, AsyncPool, AsyncTlsPool};
use skytable::aio::{Connection, TlsConnection};
async fn run() {
    // non-TLS (TCP pool)
    let notls_manager = ConnectionManager::new_notls("127.0.0.1".into(), 2003);
    let notls_pool = AsyncPool::builder()
       .max_size(10)
       .build(notls_manager)
       .await
       .unwrap();

    // TLS pool
    let tls_manager = ConnectionManager::new_tls(
        "127.0.0.1".into(), 2003, "cert.pem".into()
    );
    let notls_pool = AsyncTlsPool::builder()
       .max_size(10)
       .build(tls_manager)
       .await
       .unwrap();
}

Structs

A ConnectionManager for connection pools. See the module level documentation for examples and more information

r2d2’s error type// async The error type returned by methods in this crate.

Enums

bb8’s error type bb8’s error type.

Type Definitions

An asynchronous non-TLS connection pool to Skytable

AsyncTlsPoolaio and (aio-ssl or aio-sslv)

An asynchronous TLS connection pool to Skytable

A non-TLS connection pool to Skytable

TlsPoolsync and (ssl or sslv)

A TLS connection pool to Skytable