Database connection pool configuration
This topic describes the configuration parameters for connection pools, including those for ZDAL, Druid, DBCP, C3P0, and Java Database Connectivity (JDBC).
Data source configuration parameters
Parameters | Description | ZDAL parameter | Druid parameter | DBCP parameter | C3P0 parameter |
Initial connections | The number of connections established when the connection pool is initialized. | prefill=true initializes connections up to minConn | initialSize(0) | initialSize(0) | initialPoolSize(3) |
Minimum connections | The minimum number of available connections. The connection pool always maintains this number of connections. | minConn(0) | minIdle(0) | minIdle(0) | minPoolSize(3) |
Maximum connections | The maximum number of available connections. If this limit is exceeded, the connection pool throws an exception that it is full. | maxConn(10) | maxActive(8) | maxActive(8) | maxActive(8) |
Idle connection timeout | Specifies the period after which the connection pool closes an idle connection. By default, MySQL closes connections after 8 hours. During a primary/standby switch, connections can become dirty, which may cause requests to fail. The timeout for OceanBase SLB is 15 minutes. You can set this parameter to 12 minutes. | idleTimeoutMinutes(30 min) | minEvictableIdleTimeMillis(30 min) | minEvictableIdleTimeMillis(30 min). This parameter takes effect only when timeBetweenEvictionRunsMillis(-1) is set to a value greater than 0. This parameter controls the asynchronous check epoch. | maxIdleTime (0 means no timeout) |
Connection acquisition timeout | If this value is too large, the application may respond slowly when the connection pool is full. | blockingTimeoutMillis(500 ms) | maxWait (-1 means no timeout) | maxWaitMillis (-1 means no timeout) | checkoutTimeout (0 means no timeout) |
Unreleased connection timeout | If a connection is not returned to the pool within this period, it is destroyed. This prevents connection leaks but can affect the time limit for transactions. | None | removeAbandonedTimeoutMillis(300 s) | removeAbandonedTimeout(300 s) | None |
JDBC configuration parameters
You can set the following important JDBC parameters in the ConnectionProperties of the connection pool or in the JdbcUrl. The following table describes these parameters.
Parameter | Description | Default value |
socketTimeout | The network read timeout. If not set, the default value is 0. This means the OS default timeout is used. | 5000 ms |
connectTimeout | The connection establishment timeout. If not set, the default value is 0. This means the OS default timeout is used. | 500 ms |
Connection pool setting recommendations
Set the minimum number of connections to two as a baseline. You can adjust this value based on your business concurrency and transaction time.
Set the idle connection timeout. The recommended value is 30 minutes.
By default, MySQL closes connections after 8 hours. This can result in dirty connections because the client is not notified. The connection pool can use mechanisms, such as heartbeats and testOnBorrow, to check if a connection is active. If a connection is idle for longer than the timeout period, the connection pool closes it.