Home Database Redis How to expand redis

How to expand redis

Jun 11, 2019 am 11:02 AM

A classmate in the team used Redis as a cache in his project and stored hotspot data in Redis. In order to improve performance, the pipeline method is used when writing Redis. When used normally, the performance and resource usage of Redis can meet the project requirements. However, when the number of visits increases, the QPS of Redis can still meet the requirements, but the CPU usage is high. has reached 90%, usually only 30%. As we all know, Redis is a single process and can only occupy 1 CPU core. When it is full, it will be 100%. It cannot use the multi-core of the machine. When the CPU reaches 100% When, it will inevitably cause a performance bottleneck. How to deal with it?

How to expand redis

Recommended: "Redis Video Tutorial"

Option 1:

The first thing that comes to mind is to increase the number of Redis servers, perform a hash operation on the stored keys on the client, and store them in different Redis servers. When reading, the same hash operation is also performed to find the corresponding Redis server. Solve the problem, but the disadvantages:

First, the client needs to change the code;

Second, the client needs to remember the addresses of all Redis servers;

This solution can be used, but can it be expanded without changing the code?

Option 2:

Build a cluster. Since the version used by the Redis server is lower than 3.0, it does not support clusters. You can only use a proxy, so I thought of the famous Redis proxy twemproxy.

The performance of twemproxy is also very good. Although it is a proxy, its impact on access performance is very small. Even the Redis author recommends it.

twemproxy is easy to use. A novice can learn to use it in less than an hour, and the key is that there is no need to change the client code. It supports almost all Redis commands and pipeline operations. You only need to change the client code. The Redis IP and PORT configured in the configuration file are changed from the original Redis IP and Port to the IP and PORT of the twemproxy service.

The client does not need to consider hash issues, twemproxy will do these, and the client is just like operating a Redis.

The word "almost" is used above because some commands, such as "keys *" are not supported

We quickly deployed twemproxy and the four following Redis machines. The test found that the CPU usage of the following four Redis units dropped, but a new problem came, twemproxy is also a single process! The performance bottleneck comes to twemproxy again!

Option 3:

Access to Redis is divided into writing and reading, similar to producers and consumers. After careful analysis, it is found that there is less writing and relatively less reading. More, this can separate reading and writing, writing to the primary, and reading from the backup. The situation encountered happens to be that reading and writing are two services. To achieve separation of reading and writing, just change the configuration information. It can be done very simply, thus dispersing the pressure on the main Redis.

The access pressure on Redis has improved here, but it is not a long-term solution. For example, when events are held and the amount of data increases, there will still be performance risks.

The final method adopted is comprehensive plan two and three, as shown in the figure below:

This method has minimal changes to existing services and can be effective The problem of alleviating redis pressure

The hash algorithm used by twemproxy on the producer side and the consumer side must be consistent, otherwise the key will not be found.

If plan 1 is also added, it will be more complicated and will not be used for the time being.

The above is the detailed content of How to expand redis. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
Is Redis a SQL or NoSQL Database? The Answer Explained Is Redis a SQL or NoSQL Database? The Answer Explained Apr 18, 2025 am 12:11 AM

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis's Role: Exploring the Data Storage and Management Capabilities Redis's Role: Exploring the Data Storage and Management Capabilities Apr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

Understanding NoSQL: Key Features of Redis Understanding NoSQL: Key Features of Redis Apr 13, 2025 am 12:17 AM

Key features of Redis include speed, flexibility and rich data structure support. 1) Speed: Redis is an in-memory database, and read and write operations are almost instantaneous, suitable for cache and session management. 2) Flexibility: Supports multiple data structures, such as strings, lists, collections, etc., which are suitable for complex data processing. 3) Data structure support: provides strings, lists, collections, hash tables, etc., which are suitable for different business needs.

Why Use Redis? Benefits and Advantages Why Use Redis? Benefits and Advantages Apr 14, 2025 am 12:07 AM

Redis is a powerful database solution because it provides fast performance, rich data structures, high availability and scalability, persistence capabilities, and a wide range of ecosystem support. 1) Extremely fast performance: Redis's data is stored in memory and has extremely fast read and write speeds, suitable for high concurrency and low latency applications. 2) Rich data structure: supports multiple data types, such as lists, collections, etc., which are suitable for a variety of scenarios. 3) High availability and scalability: supports master-slave replication and cluster mode to achieve high availability and horizontal scalability. 4) Persistence and data security: Data persistence is achieved through RDB and AOF to ensure data integrity and reliability. 5) Wide ecosystem and community support: with a huge ecosystem and active community,

Redis: Understanding Its Architecture and Purpose Redis: Understanding Its Architecture and Purpose Apr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

Redis: Classifying Its Database Approach Redis: Classifying Its Database Approach Apr 15, 2025 am 12:06 AM

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

Redis: How It Acts as a Data Store and Service Redis: How It Acts as a Data Store and Service Apr 24, 2025 am 12:08 AM

Redisactsasbothadatastoreandaservice.1)Asadatastore,itusesin-memorystorageforfastoperations,supportingvariousdatastructureslikekey-valuepairsandsortedsets.2)Asaservice,itprovidesfunctionalitieslikepub/submessagingandLuascriptingforcomplexoperationsan

Redis: Exploring Its Features and Functionality Redis: Exploring Its Features and Functionality Apr 19, 2025 am 12:04 AM

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

See all articles