pub struct PoolSizingAdvisor { /* private fields */ }Expand description
Connection pool pressure monitor with scaling recommendations.
Call PoolSizingAdvisor::evaluate with current PoolMetrics to get a
PoolSizingRecommendation, or call PoolSizingAdvisor::start to launch a
background task that polls the adapter automatically.
Note: This monitor operates in recommendation mode only. The pool is not
resized at runtime — act on fraiseql_pool_tuning_* events by adjusting
max_connections in fraiseql.toml and restarting the server.
Implementations§
Source§impl PoolSizingAdvisor
impl PoolSizingAdvisor
Sourcepub const fn new(config: PoolPressureMonitorConfig) -> Self
pub const fn new(config: PoolPressureMonitorConfig) -> Self
Create a new pool pressure monitor with the given configuration.
Sourcepub fn evaluate(&self, metrics: &PoolMetrics) -> PoolSizingRecommendation
pub fn evaluate(&self, metrics: &PoolMetrics) -> PoolSizingRecommendation
Evaluate current pool metrics and return a scaling decision.
This method is pure computation — no I/O, no async. It updates internal
sample counters so consecutive calls with the same condition accumulate
toward samples_before_action.
Sourcepub fn adjustments_total(&self) -> u64
pub fn adjustments_total(&self) -> u64
Total number of resize operations applied or recommended.
Sourcepub fn recommended_size(&self) -> u32
pub fn recommended_size(&self) -> u32
Current recommended pool size (0 = not yet sampled).
Sourcepub fn start<A: DatabaseAdapter + 'static>(
self: Arc<Self>,
adapter: Arc<A>,
resize_fn: Option<Arc<dyn Fn(usize) + Send + Sync>>,
) -> JoinHandle<()>
pub fn start<A: DatabaseAdapter + 'static>( self: Arc<Self>, adapter: Arc<A>, resize_fn: Option<Arc<dyn Fn(usize) + Send + Sync>>, ) -> JoinHandle<()>
Start a background polling task.
The task samples adapter.pool_metrics() every tuning_interval_ms
milliseconds and calls Self::evaluate. If resize_fn is
provided, it is called with the new pool size whenever a resize is
decided. If resize_fn is None, the tuner operates in
recommendation mode: it updates recommended_size and logs a
warning without modifying the pool.
Returns a tokio::task::JoinHandle that can be aborted for shutdown.
Auto Trait Implementations§
impl !Freeze for PoolSizingAdvisor
impl RefUnwindSafe for PoolSizingAdvisor
impl Send for PoolSizingAdvisor
impl Sync for PoolSizingAdvisor
impl Unpin for PoolSizingAdvisor
impl UnsafeUnpin for PoolSizingAdvisor
impl UnwindSafe for PoolSizingAdvisor
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more