The connection pool feature in cluster proxy mode pools and reuses connections from proxies to databases (DBs). This prevents the exhaustion of backend DB connections caused by specific stateful commands and helps ensure the stability of your Tair (Redis OSS-compatible) instance.
Scenarios
In the proxy mode of a cloud native cluster instance, standard commands are forwarded through shared connections. An increase in client connections does not affect the number of backend DB connections. When your business logic includes specific stateful commands, the connection between a proxy and a data node switches from shared mode to exclusive mode.
In exclusive mode, each client connection establishes a corresponding exclusive connection on the data node. In high-concurrency scenarios, this causes the number of connections on the data node to grow linearly with the number of client connections. This can trigger a max number of clients reached error and lead to a service interruption.
When you use watch or blocking requests, scaling out by increasing the number of shards does not resolve the issue of too many connections on a single shard.
The commands that trigger exclusive mode include the following:
Transaction commands:
MULTI/EXEC(afterWATCH)Blocking commands:
BLPOP,BRPOP,BRPOPLPUSH,XREAD ... BLOCK ...
The connection pool feature pools and reuses exclusive connections from proxies to data nodes. This reduces the number of connections on data nodes and prevents request failures caused by exceeding the connection limit.
Architecture
The connection pool feature runs independently on each proxy child instance. Each proxy maintains a dedicated connection pool for its connections to each data node.
Example:
Without a connection pool, each connection between a client and a proxy establishes a separate connection to each backend data shard it accesses. For example, if 10 client connections all access 5 shards, a total of 10 × 5 = 50 connections are created.
When you enable the connection pool, the proxy maintains a limited connection pool for each data shard. Client requests then reuse the connections in these pools. This significantly reduces the number of database connections that are actually established. For example, for the same 10 client connections, each shard might only need to maintain 2 connections in its pool, resulting in a total of only 2 × 5 = 10 connections.
Workflow:
When a client connection (Client Conn) initiates a request in exclusive mode, the proxy node retrieves an idle connection from the corresponding data shard's connection pool.
Pool hit: If an idle connection is available in the pool, the proxy immediately attaches the connection to the client connection to forward the request. After the request is complete, the connection is detached and returned to the connection pool for other clients to reuse.
Pool miss: If no idle connections are available in the pool, the proxy creates a new connection. After the request is complete:
If the total number of connections in the pool has not reached the upper limit (
private_conn_pool_max_idle_per_db), the connection is added to the pool.If the total number of connections in the pool has reached the upper limit, the connection is immediately released (short-lived connection mode).
This optimization greatly reduces connection management overhead on the database, decreases resource overhead, and improves database stability and throughput.
Applicability
The instance must meet the following requirements:
Deployment mode: Cloud native. You can change the deployment mode from classic to cloud native.
Instance architecture: Cluster. You can change the instance architecture from standard to cluster.
Connection mode: Proxy mode.
Proxy version: 7.0.17 or later. If your version is earlier, you can upgrade the proxy version.
Enable the connection pool feature
You can enable the connection pool feature by modifying an instance parameter. This operation supports hot updates and does not require an instance restart. It does not affect your services.
Go to the Instances page. In the top navigation bar, select a region. Then, click the ID of the target instance.
In the navigation pane on the left, click Parameter Settings.
In the parameter list, find
private_conn_pool_enabledand click Modify in the Actions column.In the dialog box that appears, set the parameter value to
1and click OK.
Afterward, you can go to the Cloud Monitor console, find the instance, and view the Connections from Proxy to DB metric under Infrastructure Monitoring to compare the data before and after you enable the feature.
Configuration details and tuning guide
Configuration name | Description | Default value | Value range |
| Enables or disables the connection pool feature. | 0 |
|
| The time to live (TTL) for idle connections in the pool, in seconds. Idle connections that are not used for longer than this time are closed. A value of | 60 |
|
| The maximum number of idle connections that each proxy node maintains for each data node. When a connection is no longer in use, if the number of idle connections in the pool has reached this limit, the connection is closed instead of being returned to the pool. | 1000 |
|
| The minimum number of idle connections that each proxy node maintains for each data node. If the number of idle connections in the pool is below this value, they are not revoked even if they exceed the | 0 |
|
Scenario-based tuning recommendations
General scenarios: Keep the default configurations. They are suitable for most services.
High-concurrency, short-lived transaction scenarios (such as flash sales)
Features: Connections are occupied for a short time, and borrowing and returning operations are frequent.
Recommendation: Set
private_conn_pool_max_idle_per_dbto a value that can cover the number of concurrent requests during peak business hours. This maximizes the connection reuse rate and avoids downgrading to short-lived connections. Use the default value forprivate_conn_idle_time_secor decrease its value to release resources faster during off-peak hours.
Long-blocking service scenarios (such as queue consumers)
Features: Connections are occupied for a long time and are not returned to the pool.
Recommendation: Increase the value of
private_conn_pool_max_idle_per_dbto accommodate the number of concurrent consumers. Setprivate_conn_pool_min_idle_per_dbto a value slightly higher than the average number of concurrent connections. This "prefetches" connections and reduces connection establishment latency when new consumers start.
Scenarios that are memory-sensitive or use small instance types
Features: Requires strict control over memory usage.
Recommendation: Decrease the values of
private_conn_pool_max_idle_per_dbandprivate_conn_pool_min_idle_per_db. Although this might slightly degrade performance by increasing the likelihood of creating short-lived connections, it conserves memory resources on data nodes.
Notes
Set a reasonable value for
private_conn_pool_min_idle_per_dbEach idle connection consumes some memory resources on the backend DB node. In instances with multiple shards and multiple proxy nodes, setting
private_conn_pool_min_idle_per_dbto a high value can lead to high memory usage.Avoid unnecessary DB context switching
When a connection from the pool is reused by a client that accesses a different DB index, the proxy must run the
SELECTcommand to switch the context. This operation increases the DB payload and request latency. In your application design, ensure that all clients use the same DB index, which is typically DB 0.Not applicable to publish/subscribe commands
The connection pool feature does not apply to publish/subscribe commands such as
SUBSCRIBEandPSUBSCRIBE. These commands permanently occupy a connection, so these connections are not managed by the pool.