当前位置:网站首页>1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
2022-07-04 00:39:00 【Xianghan collection】
Redis
brief introduction
Redis It's completely open source and free , Is a high-performance key-value Type of in-memory database . The whole database system is loaded in memory for operation , Periodically through asynchronous operation Put the database data flush Save to hard disk . Because it's a pure memory operation ,Redis Performance is excellent , Can handle over per second 10 Ten thousand read and write operations , Is the fastest known Key-Value DB.
Redis It's not just the performance that's outstanding ,Redis The greatest charm is Support to save multiple data structures , In addition, a single value The maximum limit of is 1GB, therefore Redis Can be used to achieve many useful functions , Let's say List To do it FIFO Double linked list , Implement a lightweight high-performance Message Queuing service , Use him Set Can do high performance tag System, etc. . in addition Redis You can also save Key-Value Set up expire Time . In conclusion , Use Redis The benefits are as follows :
1. Fast , Because the data is in memory , The speed of reading is zero 110000 Time /s, The speed of writing is 81000 Time /s;
2. Support for rich data types , Support string,list,set,sorted set,hash;
3. Support transactions , The operations are all atomic , Changes to the data are either fully implemented , Or none at all , The execution of any command in the transaction failed , The rest of the orders are still being carried out . in other words Redis Affairs do not guarantee atomicity , Rollback is not supported either ; Multiple commands in the transaction are sent to the server at one time , The server is executing the command , Will not execute command requests from other clients .
4. Rich features : Available for caching , news ( Support publish/subscribe notice ), Press key Set expiration time , It will be deleted automatically after expiration , Specific elimination strategies include :
4.1.volatile-lru: From a dataset for which an expiration time has been set , Select the least recently used data
4.2.volatile-ttl: From a dataset for which an expiration time has been set , Select the data that is about to expire and eliminate it
4.3.volatile-random: From a dataset for which an expiration time has been set , Randomly selected data
4.4.allkeys-lru: From all data sets , Select the least recently used data
4.5.allkeys-random: From all data sets , Randomly selected data
4.6.no-enviction: Ban data obsolescence
The specific expiration key strategies are : Delete regularly ( Delete when the cache expires , establish timer Consumption CPU), Lazy deletion ( Check when getting , Do not get and keep in memory , Not memory friendly ), Delete periodically (CPU And memory )
5. Support data persistence , The data in memory can be saved on disk , When you restart, you can load it again for use ;
6. Support data backup , namely master - slave Mode data backup .
Redis The main shortcoming Database capacity is limited by physical memory , Cannot be used as high-performance read-write of massive data , therefore Redis Suitable scenes are mainly limited to High performance operation and operation with small amount of data .
Common architecture
standalone mode
Stand alone mode, as the name suggests, is to install a Redis, Start it up , Business call is just . For example, some simple applications , It is not necessary to ensure that this mode can be used in case of high availability .
advantage
- Simple deployment ;
- The cost is low , No spare nodes ;
- High performance , A single machine does not need to synchronize data , Natural consistency of data .
shortcoming
- Reliability assurance is not very good , Single node has the risk of downtime .
- Single machine high performance is limited by CPU Handling capacity of ,Redis It's single threaded .
stand-alone Redis Capable of carrying QPS( Query rate per second ) About tens of thousands . Depending on the complexity of the business operation ,Lua Script complexity is extremely high . If it's simple key value Query that performance will be very high .
Suppose there are tens of millions of 、 Hundreds of millions of users visit at the same time Redis,QPS achieve 10 ten thousand +. These requests come here , stand-alone Redis Just hang up . The bottleneck of the system is Redis On the single machine problem , At this time, you can use the Master slave copy Solve the problem , To achieve high concurrency of the system .
Master slave copy
Redis Copy (Replication) The feature allows the user to follow one Redis Server to create any number of replicas of that server , Where the replicated server is the primary server (Master), The replica created by copying is from the server (Slave). As long as the network connection between the master and slave servers is working , The master server will synchronously update the data written to itself to the slave server , So as to ensure that the data of the master and slave servers are the same .
Data replication is one-way , From master to slave only , The simple understanding is that the slave node only supports read operations , Write not allowed . It mainly uses the master-slave architecture in high concurrency scenarios . The problem to be considered in master-slave mode is : When Master The node is down , A new one needs to be elected Master node , In order to ensure the high availability of services .
advantage
- Master/Slave The role is easy to expand horizontally ,QPS increase , increase Slave that will do ;
- Reduce Master Reading pressure , Handed over to Slave node ;
- The primary node is down , As the backup of the master node, the slave node can continue to provide services at any time ;
shortcoming
- Reliability assurance is not very good , If the primary node fails, the write service cannot be provided ;
- There is no solution to the pressure on the master node to write ;
- data redundancy ( For high concurrency 、 High availability and performance , Redundancy is generally allowed );
- Once the primary node goes down , From node to master node , You need to modify the master node address of the application side , You also need to command all slaves to copy the new master , The whole process needs human intervention ;
- The write ability of the master node is limited by a single machine ;
- The storage capacity of the primary node is limited by the single machine .
边栏推荐
- MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
- Regular expression of shell script value
- Att & CK actual combat series - red team actual combat - V
- Introduction to thread pool
- How to be a professional software testing engineer? Listen to the byte five year old test
- Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Is the low commission link on the internet safe? How to open an account for China Merchants Securities?
- 2-Redis架构设计到使用场景-四种部署运行模式(下)
- 1-Redis架构设计到使用场景-四种部署运行模式(上)
- Similarities and differences of text similarity between Jaccard and cosine
猜你喜欢
Analysis: misunderstanding of choosing WMS warehouse management system
STM32 GPIO CSDN creative punch in
What does redis do? Redis often practices grammar every day
Interview script of Software Test Engineer
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
How to be a professional software testing engineer? Listen to the byte five year old test
老姜的特点
OS interrupt mechanism and interrupt handler
(Introduction to database system | Wang Shan) Chapter V database integrity: Exercises
A dichotomy of Valentine's Day
随机推荐
12. Go implementation of integer to Roman numeral and leetcode
Self study software testing. To what extent can you go out and find a job?
Stock price forecast
The difference between objects and objects
URL (data:image/png; Base64, ivborw0k... Use case
Is the account opening of Guoyuan securities really safe and reliable
Struct in linked list
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
[GNN] hard core! This paper combs the classical graph network model
Reading notes on how programs run
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing
AI Challenger 2018 text mining competition related solutions and code summary
Analysis: misunderstanding of choosing WMS warehouse management system
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
[about text classification trick] things you don't know
The difference between fetchtype lazy and eagle in JPA
Sorry, Tencent I also refused
Regular expression of shell script value
Gauss elimination method and template code