pub struct ConnectionPool {
pub config: PoolConfig,
pub connections: Arc<Mutex<HashMap<String, ConnectionHandle>>>,
pub semaphore: Arc<Semaphore>,
pub wait_queue: Arc<Mutex<Vec<Arc<Notify>>>>,
pub stats: Arc<RwLock<PoolStats>>,
pub health_checker: Arc<Mutex<ConnectionHealthChecker>>,
pub is_running: Arc<Mutex<bool>>,
}Expand description
Connection pool with advanced management
Fields§
§config: PoolConfig§connections: Arc<Mutex<HashMap<String, ConnectionHandle>>>§semaphore: Arc<Semaphore>§wait_queue: Arc<Mutex<Vec<Arc<Notify>>>>§stats: Arc<RwLock<PoolStats>>§health_checker: Arc<Mutex<ConnectionHealthChecker>>§is_running: Arc<Mutex<bool>>Implementations§
Source§impl ConnectionPool
impl ConnectionPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Create a new connection pool
Sourcepub async fn get_connection(&self) -> Result<ConnectionHandle, String>
pub async fn get_connection(&self) -> Result<ConnectionHandle, String>
Get a connection from the pool
Sourcepub async fn release_connection(&self, handle: ConnectionHandle)
pub async fn release_connection(&self, handle: ConnectionHandle)
Release a connection back to the pool
Sourceasync fn find_or_create_connection(&self) -> Result<ConnectionHandle, String>
async fn find_or_create_connection(&self) -> Result<ConnectionHandle, String>
Find or create a healthy connection
Sourceasync fn start_health_monitoring(&self)
async fn start_health_monitoring(&self)
Start health monitoring
Sourceasync fn start_connection_cleanup(&self)
async fn start_connection_cleanup(&self)
Start connection cleanup
Sourceasync fn initialize_min_connections(&self)
async fn initialize_min_connections(&self)
Initialize minimum connections
Sourceasync fn check_connection_health(&self) -> Result<(), String>
async fn check_connection_health(&self) -> Result<(), String>
Check connection health
Sourceasync fn cleanup_stale_connections(&self) -> usize
async fn cleanup_stale_connections(&self) -> usize
Cleanup stale connections
Sourcepub async fn get_active_count(&self) -> usize
pub async fn get_active_count(&self) -> usize
Get active connection count
Sourcepub async fn get_healthy_count(&self) -> usize
pub async fn get_healthy_count(&self) -> usize
Get healthy connection count
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if pool is running
Source§impl ConnectionPool
Utility functions for connection pooling
impl ConnectionPool
Utility functions for connection pooling
Sourcepub fn default_pool() -> Self
pub fn default_pool() -> Self
Create a connection pool with default configuration
Sourcepub fn high_performance_pool() -> Self
pub fn high_performance_pool() -> Self
Create a high-performance pool
Sourcepub fn conservative_pool() -> Self
pub fn conservative_pool() -> Self
Create a conservative pool
Sourcepub fn calculate_optimal_pool_size() -> usize
pub fn calculate_optimal_pool_size() -> usize
Calculate optimal pool size based on system resources
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConnectionPool
impl !RefUnwindSafe for ConnectionPool
impl Send for ConnectionPool
impl Sync for ConnectionPool
impl Unpin for ConnectionPool
impl !UnwindSafe for ConnectionPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Applies the layer to a service and wraps it in [
Layered].