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

Configuring Redis Client Retry

Updated on 2024-11-26 GMT+08:00

Importance of Retry

Both the client and server may encounter temporary faults (such as transient network or disk jitter, service unavailability, or invoking timeout, due to infrastructure or running environment reasons). As a result, Redis operations may fail. You can design automated retry mechanisms to reduce the impact of such faults and ensure successful execution.

Scenarios Where Redis Operations Fail

Scenario

Description

Master/standby switchover triggered by a fault

If the master node is faulty due to Redis underlying hardware or other reasons, a master/standby switchover is triggered to ensure that the instance is still available. A master/standby switchover causes instance disconnection for 15 to 30s:

Read-only during specification modification

During specification modification, the instance may be disconnected for seconds and read-only for minutes.

Request blockage caused by slow queries

Operations whose time complexity is O(N) cause slow queries and request blockage. In this case, other client requests may temporarily fail.

Complex network environment

Due to the complex network environment between the client and the Redis server, network jitter, packet loss, and data retransmission may occur occasionally. In this case, client requests may temporarily fail.

Complex hardware issues

Client requests may temporarily fail due to occasional hardware faults, such as VM HA and disk latency jitter.

Recommended Retry Rules

Retry Rule

Description

Retry only idempotent operations.

Timeout may occur in any of the following phases:

  • A command is successfully sent by the client but has not reached Redis.
  • The command has reached Redis, but the execution times out.
  • Redis has executed the command, but the result returned to the client times out.

A retried operation may be repeatedly executed in Redis. Therefore, not all operations are suitable to be retried. You are advised to retry only idempotent operations, such as running the SET command. For example, if you run the SET a b command multiple times, the value of a can only be b or the execution fails. If you run LPUSH mylist a, which is not idempotent, mylist may contain multiple a elements.

Configure proper retry times and interval.

Configure the retry times and interval based on service requirements in actual scenarios to prevent the following problems:

  • If the number of retries is insufficient or the interval is too long, the application may fail to complete operations.
  • If the number of retries is too large or the interval is too short, the application may occupy too many system resources and the server may be blocked due to too many requests.

Common retry interval policies include immediate retry, fixed-interval retry, exponential backoff retry, and random backoff retry.

Avoid retry nesting.

Retry nesting may cause the retry interval to be exponentially amplified.

Record retry exceptions and print failure reports.

During retry, you can print retry error logs at the WARN level.

Jedis Client Retry Configurations

  • Retries are not supported in native JedisPool mode (for single-node, master/standby, and Proxy Cluster instances). However, you can implement retries by referring to JedisClusterCommand.
  • Retries are supported in JedisCluster mode. You can set the maxAttempts parameter to define the number of retry times when a failure occurs. The default value is 5. By default, all JedisCluster operations invoke the retry method.

    Example code:

    @Bean
    JedisCluster jedisCluster() {
        Set<HostAndPort> hostAndPortsSet = new HashSet<>();
        hostAndPortsSet.add(new HostAndPort("{dcs_instance_address}", 6379));
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(100);
        jedisPoolConfig.setMinIdle(1);
        jedisPoolConfig.setMaxTotal(1000);
        jedisPoolConfig.setMaxWaitMilis(2000);
        jedisPoolConfig.setMaxAttempts(5);
        return new JedisCluster(hostAndPortsSet, jedisPoolConfig);
    }
Table 1 Recommended Jedis connection pool parameter settings

Parameter

Description

Recommended Setting

maxTotal

Maximum number of connections

Set this parameter based on the number of HTTP threads of the web container and reserved connections. Assume that the maxConnections parameter of the Tomcat Connector is set to 150 and each HTTP request may concurrently send two requests to Redis, you are advised to set this parameter to at least 400 (150 x 2 + 100).

Limit: The value of maxTotal multiplied by the number of client nodes (CCE containers or service VMs) must be less than the maximum number of connections allowed for a single DCS Redis instance.

For example, if maxClients of a master/standby DCS Redis instance is 10,000 and maxTotal of a single client is 500, the maximum number of clients is 20.

maxIdle

Maximum number of idle connections

Use the same configuration as maxTotal.

minIdle

Minimum number of idle connections

Generally, you are advised to set this parameter to 1/X of maxTotal. For example, the recommended value is 100.

In performance-sensitive scenarios, you can set this parameter to the value of maxIdle to prevent the impact caused by frequent connection quantity changes. For example, set this parameter to 400.

maxWaitMillis

Maximum waiting time for obtaining a connection, in milliseconds

The recommended maximum waiting time for obtaining a connection from the connection pool is the maximum tolerable timeout of a single service minus the timeout for command execution. For example, if the maximum tolerable HTTP failure is 15s and the timeout of Redis requests is 10s, set this parameter to 5s.

timeout

Command execution timeout, in milliseconds

This parameter indicates the maximum timeout for running a Redis command. Set this parameter based on the service logic. You are advised to set this timeout to least 210 ms to ensure network fault tolerance. For special detection logic or environment exception detection, you can adjust this timeout to seconds.

minEvictableIdleTimeMillis

Idle connection eviction time, in milliseconds. If a connection is not used for a period longer than this, it will be released.

If you do not want the system to frequently re-establish disconnected connections, set this parameter to a large value (xx minutes) or set this parameter to –1 and check idle connections periodically.

timeBetweenEvictionRunsMillis

Interval for detecting idle connections, in milliseconds

The value is estimated based on the number of idle connections in the system. For example, if this interval is set to 30s, the system detects connections every 30s. If an abnormal connection is detected within 30s, it will be removed. Set this parameter based on the number of connections. If the number of connections is too large and this interval is too short, request resources will be wasted. If there are hundreds of connections, you are advised to set this parameter to 30s. The value can be dynamically adjusted based on system requirements.

testOnBorrow

Indicates whether to check the connection validity using the ping command when borrowing connections from the resource pool. Invalid connections will be removed.

If your service is extremely sensitive to connections and the performance is acceptable, you can set this parameter to True. Generally, you are advised to set this parameter to False to enable idle connection detection.

testWhileIdle

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

True

testOnReturn

Indicates whether to check the connection validity using the ping command when returning connections to the resource pool. Invalid connections will be removed.

False

maxAttempts

Number of connection retries when JedisCluster is used

Recommended value: 3–5. Default value: 5.

Set this parameter based on the maximum timeout intervals of service APIs and a single request. The maximum value is 10. If the value exceeds 10, the processing time of a single request is too long, blocking other requests.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback