Lightweight 0.20260921.0
Loading...
Searching...
No Matches
Lightweight::PoolConfig Struct Reference

#include <Pool.hpp>

Public Member Functions

constexpr std::chrono::milliseconds MaxIdleTime () const noexcept
 
constexpr std::chrono::milliseconds MaxLifetime () const noexcept
 

Public Attributes

size_t initialSize {}
 Initial number of data mappers to pre-create and store in the pool, must be less than or equal to maxSize.
 
size_t maxSize {}
 
GrowthStrategy growthStrategy { GrowthStrategy::BoundedWait }
 
ValidateOnBorrow validateOnBorrow { ValidateOnBorrow::Yes }
 
std::chrono::milliseconds::rep maxIdleTimeMs {}
 
std::chrono::milliseconds::rep maxLifetimeMs {}
 
size_t preparedStatementCacheCapacity { PreparedStatementCacheCapacityDefault }
 

Detailed Description

Structure to hold the configuration of the pool, including the initial size, maximum size and growth strategy. Structure is used as a template parameter for the Pool class to configure its behavior at compile time.

Note
The lifetime bounds are expressed as plain millisecond counts rather than std::chrono::milliseconds because this structure is used as a non-type template parameter: std::chrono::duration keeps its representation private and is therefore not a structural type. Use PoolConfig::MaxIdleTime and PoolConfig::MaxLifetime to read them back as durations.

Definition at line 91 of file Pool.hpp.

Member Function Documentation

◆ MaxIdleTime()

constexpr std::chrono::milliseconds Lightweight::PoolConfig::MaxIdleTime ( ) const
inlineconstexprnoexcept
Returns
maxIdleTimeMs as a duration.

Definition at line 147 of file Pool.hpp.

References maxIdleTimeMs.

◆ MaxLifetime()

constexpr std::chrono::milliseconds Lightweight::PoolConfig::MaxLifetime ( ) const
inlineconstexprnoexcept
Returns
maxLifetimeMs as a duration.

Definition at line 153 of file Pool.hpp.

References maxLifetimeMs.

Member Data Documentation

◆ initialSize

size_t Lightweight::PoolConfig::initialSize {}

Initial number of data mappers to pre-create and store in the pool, must be less than or equal to maxSize.

Definition at line 94 of file Pool.hpp.

◆ maxSize

size_t Lightweight::PoolConfig::maxSize {}

Maximum number of data mappers that can exist in the pool, must be greater than or equal to initialSize this is used for the Bounded* strategies to determine when to block or when to stop accepting returned data mappers, for the UnboundedGrow strategy this is ignored

Definition at line 98 of file Pool.hpp.

◆ growthStrategy

GrowthStrategy Lightweight::PoolConfig::growthStrategy { GrowthStrategy::BoundedWait }

Strategy to determine how the pool should grow when there are no idle data mappers available, default is BoundedWait which blocks until a data mapper is returned to the pool

Definition at line 101 of file Pool.hpp.

◆ validateOnBorrow

ValidateOnBorrow Lightweight::PoolConfig::validateOnBorrow { ValidateOnBorrow::Yes }

Whether a connection is checked for liveness before it is handed to a caller, enabled by default.

See also
ValidateOnBorrow

Definition at line 106 of file Pool.hpp.

◆ maxIdleTimeMs

std::chrono::milliseconds::rep Lightweight::PoolConfig::maxIdleTimeMs {}

Maximum time in milliseconds a connection may sit idle in the pool before it is retired instead of handed out again; 0 (the default) disables the bound.

Set this below any idle timeout imposed by the network path (a firewall or NAT dropping idle flows) or by the server, so a connection is never idle long enough to be reaped behind the pool's back. This removes the failure mode that ValidateOnBorrow can only detect, and then only when the driver has noticed.

Note
Retirement is lazy: it happens when the pool is next used, so a pool that goes completely idle keeps its connections until the next Pool::Acquire. Correctness is unaffected — an expired connection is discarded rather than handed out — but the pool does not shrink on its own.

Definition at line 120 of file Pool.hpp.

Referenced by MaxIdleTime().

◆ maxLifetimeMs

std::chrono::milliseconds::rep Lightweight::PoolConfig::maxLifetimeMs {}

Maximum total age in milliseconds of a connection, counted from when it was created, after which it is retired rather than reused; 0 (the default) disables the bound.

Unlike validateOnBorrow, this retires connections that are perfectly alive but no longer appropriate: after a failover or a rolling restart a pooled connection stays bound to the old node, and nothing else in the pool will ever move it. Setting this shorter than any connection-age ceiling imposed by the database or the infrastructure also means connections are retired while idle, which is free, rather than being cut mid-query by something else.

Note
Retirement is lazy, as described for maxIdleTimeMs.

Definition at line 132 of file Pool.hpp.

Referenced by MaxLifetime().

◆ preparedStatementCacheCapacity

size_t Lightweight::PoolConfig::preparedStatementCacheCapacity { PreparedStatementCacheCapacityDefault }

Prepared-statement cache capacity given to the connection of every data mapper this pool creates, i.e. how many already-prepared ODBC statement handles that connection keeps for reuse. Zero (the default) leaves the cache disabled, exactly as an unpooled connection.

The bound is per connection, not per pool: a pool may hold up to maxSize connections, each with its own cache of this size, so the live prepared handles a fully warmed pool holds on the server are maxSize * preparedStatementCacheCapacity. Size it against the backend's per-session limit on prepared statements, not against the number of distinct queries alone.

See also
SqlConnection::SetPreparedStatementCacheCapacity for what enabling the cache implies.

Definition at line 144 of file Pool.hpp.


The documentation for this struct was generated from the following file: