In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the meaning of redis high availability". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Preface
Recently in watching redis, there are some experience, in order not to forget, now record it.
I try to start from the problem, step by step, to give you a better reading experience, as follows
What is caching and why do you have it?
How to implement caching-in-process caching
How caching is implemented-process-level caching
As a process-level database, redis has many advantages.
High availability implementation of redis
What is caching and why do you have it?
Generally speaking, we store the data in the database. For some frequently queried businesses, such as users accessing a certain resource, we usually check whether the user has this access right by querying the database. This business is characterized by high query frequency. Querying the database is a relatively heavy operation, and the main time-consuming operations are the query time of the database itself and the network time. If you put some commonly used data in the running memory of the program, as the program starts, the information in the database is loaded into memory, which reduces the time-consuming of network interaction and query of the database itself.
How to implement caching-in-process caching
This is to open up a piece of memory when writing a program, which is used as a cache for the program to use.
Advantages
No network transmission is required.
No switching between threads is required.
Cache updates are convenient. Because it is the memory area within the program, which area I need to update, I can directly locate the memory location and update it.
Shortcoming
The expansibility is poor. It is also an example of a mall. Users want to see their shopping cart. Suppose we use token for status maintenance. I parse token and extract user id to see if they have permission for this business operation. If there is only one program deployed, no problem at all. However, in order to meet the rapid growth of users in the future, there can be problems through the horizontal expansion program of nginx. If we deploy two programs in parallel, the user logs in, program a processes the request, and token stores the user's permission information in its own memory area. When the user initiates another business request, program b accepts the request. Program b gets the user's token, extracts user information, queries its own memory area, and finds that without this user information, it judges that the user does not have access rights.
If it is a horizontal expansion, it is likely to waste memory. Many programs have their own memory areas, but the memory areas are basically the same.
How caching is implemented-caching benefits at the process level
Save memory resources.
The separation of responsibilities is clearer
Shortcoming
Increase network transmission
Increase switching between threads
Single point, risky.
As a process-level database, redis has many advantages.
Support for highly available deployment
In order to reduce the delay of overall network transmission, a new idea is proposed:
Suppose I am the boss of Oriental Dumpling Wang in Xinjiekou, providing food delivery service. I have two couriers. Suppose my meal is prepared in advance.
At 12:00, Xiaoqiang of the Capital Science and Technology Building ordered an order of dumplings. The courier 1 will deliver the food, which can be delivered in ten minutes, and return to the hotel in another ten minutes.
At 12:02, Xiao Hong in the Capital Science and Technology Building ordered a dumpling. The courier 2 will deliver the food, which can be delivered in ten minutes, and he will return to the hotel in another ten minutes.
At 12:03, Xiaohua of the Capital Science and Technology Building ordered an order of dumplings. There was no courier to deliver the food: courier 1 will not be back until 12:20, courier 2 will not be back until 12:22. wait for
At 12:04, Trump ordered five dumplings in the Capital Science and Technology Building, and there were no couriers to deliver the food: courier 1 will not be back until 12:20 and courier 2 will not be back until 12:22. wait for
At 12:05, Clinton of the Capital Science and Technology Building ordered five dumplings, and there was no courier to deliver the food: courier 1 will not be back until 12:20, courier 2 will not be back until 12:22. wait for
At 12:20, the courier 1 received an order for floret to deliver the food.
At 12:22, courier 2 received an order from Trump to deliver food.
If Trump and Xiaoqiang Xiaohong are from the same company, Trump will be upset. They are both set at the same time. Why are they here, but mine hasn't arrived yet?
Is there a solution?
Reduce the time spent on each trip. For example, couriers used to ride bicycles, now motorcycles, cars, rockets.
Increase the number of couriers. It turned out to be two, so I'll recruit a dozen more.
The courier strives for a little more goods each time. For example, in the above example, in just five minutes, there were 5 orders for a total of 13 dumplings in Beijing Science and Technology Mansion. Assuming that a courier's trunk can hold 10 cents of dumplings, then at 12:05, courier 1 will deliver the first four orders, a total of 8, and courier 2 will deliver the fifth order, one for 5 cents. So Trump can have dinner with Xiao Qiang.
In the computer, these three solutions correspond to
Reduce the time spent on each trip. Round trip time: start from the sender to send the data until the sender receives the confirmation of the receiver's reply. The way of data transmission is simply like this: first, the data is converted into a byte stream, and then it is converted into electromagnetic waves through a device (modulation decoder), which is transmitted through network lines or radio waves, and the receiver receives the radio waves. convert it into a byte stream, and then convert it into specific data available to the program. Whether the brain is a little big, the optimization of this process may not be what software engineers can do.
Throughput: the amount of data passing through a network per unit of time. This optimization may not be what software engineers can do.
Buffering the transmitted data to reduce the overall network delay.
The third idea has been adopted in many places, for example, mail servers use this idea to download new mail more quickly.
Redis also adopts the third solution.
Interested students can refer to the official documents.
Https://redis.io/topics/pipelining
High availability implementation of redis
Highly available business requirements, when the caching service is not available for some reason, you can switch to the caching service of another machine.
Difficulties that may be involved
How do I judge that the cache service is not available?
How do I notify all clients using the caching service when it is not available? now that you have a problem with the one you are accessing, you should visit another good
How the data stored by the backup cache service is consistent with the data stored by the cache service being used
When the node I lost in down can be used again, how can I add it to the cache and use it as a spare?
I try to put forward my own thoughts on these questions.
1 how can I judge that the cache service is not available
I need to know how each client uses the cache service. If everyone says there is a problem with the cache, then change to a good one. If at least half of the customers think there is a problem, then there is a problem with the cache. Something like this must be used by who knows. Ha ha
2 when the cache is not available, how do I notify all clients using the cache service? now that you have a problem with the one you are accessing, you should visit another good
This is to record the client that needs to use the cache service when the program is deployed. When I want to switch the cache, I just notify the client one by one.
3 how the data stored by the backup cache service is consistent with the data stored by the cache service being used
This is actually very simple, just give a copy of the request copy for accessing the cache to the backup cache. Of course, who should do this operation? If it were me, I would do it in client. After I finish an operation, I add the operation to a cache queue and let the background thread handle the copy operation.
4 when the node dropped by my down can be used again, how can I add it to the cache and use it as a spare?
There are two ways to do this. One is that the cache dropped by down directly informs me that I am alive and I want to be a spare. What do you think we should do? One is that I take a look at the node that down has dropped from time to time, and if it is good, I will allow him to use it as a spare.
Now let's see how redis does it.
It proposes a type of person: the Sentinel, whose duties are as follows
Surveillance. He is responsible for checking the health of the cache and the spare tire.
Let me know. When he monitors an exception, he can notify the administrator or other programs.
Automatic failure recovery. When caching is not available, start a recovery process when the spare requests caching, and when client uses the cache, you will be notified that you need to change to a spare.
Configure the provider. Client cannot access the cache directly. You need to ask this guy which cache I should access first.
For the above four questions, let's see how redis does it.
1 how can I judge that the cache service is not available
He proposed a concept of threshold quorum, which determines that a cache is unavailable only if and only if these two conditions are met.
Several sentinels agree that the current cache is not available
In order to find a Sentinel to start the recovery process, the Sentinels need to elect a leader who will perform the operation.
This is a bit of a fool, if this is the deployment of the cache service
Server001 master soilder01
Server002 replica1 soilder02
The threshold is set to 1, when soilder02 says master cannot be used, ok meets the first condition, then the second condition is to find a sentry to start the recovery program, there is only one soilder left, how to elect, do you still need an election?
Of course, this situation can be avoided, for example, sentinels can also be arranged in the client.
Server001 master soilder01
Server002 replica1 soilder02
Server003 client1 soilder03
Server004 client2 soilder04
I can solve this problem by setting the threshold to 1.
2 when the cache is not available, how do I notify all clients using the cache service? now that you have a problem with the one you are accessing, you should visit another good
The client accesses the cache service indirectly through the sentinel. The disadvantage of this is that it increases a layer of network consumption. Originally, I accessed the cache directly to get the data, but now I need to ask the Sentinel what the cache address is now, and then I will access the cache service according to this address.
3 how the data stored by the backup cache service is consistent with the data stored by the cache service being used
When the spare tire is connected to the cache master, master is responsible for keeping the spare tire consistent with itself.
4 when the node dropped by my down can be used again, how can I add it to the cache and use it as a spare?
When the spare tire is connected to the cache master, master is responsible for keeping the spare tire consistent with itself.
This is the end of the content of "what does redis High availability mean?" Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.