Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ GeminiDB/ GeminiDB Redis API/ Development Reference/ Configuring Parameters for a Client Connection Pool

Configuring Parameters for a Client Connection Pool

Updated on 2025-01-03 GMT+08:00

Setting proper parameters for a connection pool can effectively improve Redis performance of the client. Improper configuration (for example, the number of maximum connections is set to a small value) may cause applications not to be connected, affecting production services. This section uses JedisPool of the Redis client Jedis as an example to describe how to use JedisPool and its parameters, providing optimal configuration reference for service developers.

Usage Instructions

Take Jedis 4.3.1 as an example. The Maven dependency configuration is as follows:

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>4.3.1</version>
    <scope>compile</scope>
</dependency>

Jedis uses Apache Commons-pool2 to manage its connection pool. When defining JedisPool, pay attention to the key parameter GenericObjectPoolConfig (Jedis). The following is an example for using this parameter:

GenericObjectPoolConfig<Jedis> config =  new GenericObjectPoolConfig<>();
config.setMaxTotal(100);
config.setMaxIdle(50);
config.setMinIdle(5);
config.setTestWhileIdle(true);
....

The initialization method of Jedis is as follows:

JedisPool pool = new JedisPool(config, host, port, timeout, password);// Create a connection pool.
try (Jedis jedis = pool.getResource()) {//Obtain a connection and automatically release the connection after the execution.
    //Run the following command on the Jedis client:
} catch (Exception e) {
    e.printStackTrace();
}
pool.close();//Close the connection pool.

Parameter Description

Jedis connections are resources managed by JedisPoo. JedisPool controls resources and protects threads. Proper GenericObjectPoolConfig configuration can improve Redis service performance and reduce resource overhead. The following table lists some important parameters and describes how to set the parameters.

Table 1 Common Jedis parameters

Jedis Parameter

Description

Default Value

Recommended Setting

maxTotal

Maximum number of concurrent connections in the current resource pool.

The number of Redis connections must be set based on the service volume. If the value is set to too large, resources are wasted. If the value is set to too small, connections cannot be obtained, affecting services.

8

The number of client nodes multiplied by the value of maxTotal cannot exceed the maximum number of Redis connections.

Assume that the QPS of a connection is about 1000 per second or millisecond and the expected QPS of a single Redis instance is 50,000. Theoretically, the required resource pool size (MaxTotal) is 50 (50000/1000).

maxIdle

Maximum number of idle connections in a resource pool.

After the number of idle connections reaches the value of maxIdle, the resource pool starts to revoke idle connections until the number of idle connections reaches the value of minIdle. This prevents empty connections from being occupied and resources from being wasted.

8

maxIdle indicates the maximum number of connections required by the service, and maxTotal indicates the margin. You are not advised to set maxIdle to a small value. Otherwise, new Jedis (new connection) overhead occurs.

minIdle

Minimum number of idle connections in a resource pool.

These connections are not revoked to prevent delayed connection creation when traffic increases.

0

10 to 20

maxWaitMillis

Maximum wait time (in milliseconds) of the invoker after the resource pool connections are used up

-1

You are advised to set a proper timeout interval to prevent application blocking after connection pools are used up.

testWhileIdle

Indicates whether to use the ping command to monitor the connection validity during idle resource monitoring. Invalid connections will be destroyed.

false

true

testOnBorrow

Indicates whether to check the connection validity (by sending a ping request) each time a connection is obtained from a resource pool. Invalid connections will be released.

false

The preset value is recommended. If this parameter is set to true, a ping command is sent before each command is executed, which affects the performance of applications with a large number of concurrent requests. If high service availability is required, set this parameter to true to ensure that the connection is valid.

testOnReturn

Indicates whether to check the connection validity (by sending a ping request) each time a connection is returned to a connection pool. Invalid connections will be released.

false

The preset value is recommended. If this parameter is set to true, a ping command is sent after each command is executed, which affects the performance of applications with a large number of concurrent requests.

timeout

Socket timeout value of Jedis, in milliseconds

2000

200 to 1000

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback