In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is snapshot persistence in redis? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
For the security of internal data, Redis will save its own data to the hard disk as a file, and automatically restore the hard disk data to redis after the server is rebooted. The process of saving the data to the hard disk is called "persistence" effect.
Snapshot persistence
Write all the data at a certain time to the hard disk. With the BGSAVE command, executing BGSAVE may cause the system to pause for a long time as memory usage increases.
Snapshot principle
We know that Redis is a single-threaded program, which is responsible for the concurrent read and write operations of multiple client sockets and the logical read and write of in-memory data structures.
At the same time of the request on the service line, Redis also needs to take a memory snapshot. Memory snapshot requires Redis to perform text IO operation, but file IO operation cannot use multiplexed API.
This means that single-threaded requests on the service line at the same time have to perform file IO operations, which can seriously drag down the performance of server requests. Another important problem is that in order not to block online business, you need to respond to client requests while persisting. At the same time of persistence, the in-memory data structure is still changing, for example, a large hash dictionary is being persisted, and as a result, a request has come to delete it, and it hasn't been persisted yet. what about Nima?
What are we going to do?
Redis uses the operating system's multi-process COW (Copy On Write) mechanism for snapshot persistence, which is interesting and little known. Multi-process COW is also an important indicator to evaluate the breadth of programmers' knowledge.
Fork (multiprocess)
During persistence, Redis calls glibc's function fork to generate a child process, snapshot persistence is completely left to the child process, and the parent process continues to process client requests. When a child process is first generated, it shares code and data segments in memory with the parent process. At this point, you can think of the father-son process as conjoined twins, sharing the body. This is the mechanism of the Linux operating system, so let them be shared as much as possible in order to save memory resources. At the moment of process separation, there is almost no significant change in memory growth. The child process does data persistence, it does not modify the existing in-memory data structure, it just traverses the data structure and then serializes it to disk. But the parent process is different, it must continuously serve the client request, and then make continuous changes to the in-memory data structure. At this point, the COW mechanism of the operating system is used to separate the data segment pages. The data segment is composed of many pages that operate as the system. When the parent process modifies the data of one of the pages, it will copy the shared page and separate it, and then modify the copied page. At this time, the corresponding page of the child process does not change, or the data at the moment when the process is generated.
As the parent process modification continues, more and more shared pages are separated, and memory continues to grow. But it will not be more than twice the size of the original data memory. In another Redis instance, the proportion of cold data used to be relatively high, so it is rare that all pages are separated, and only part of the pages are separated. Each page is only 4K in size, and there are usually thousands of pages in an Redis instance.
Because the data of the child process does not change, the data it can see in memory is frozen in the moment the process is generated, and will never change again, which is why the persistence of Redis is called "snapshot". Then the child process can traverse the data with great peace of mind and serialize the write disk.
This is the answer to the question about snapshot persistence in redis. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.