Redis memory optimization comprehension and storage Summary

Source: Internet
Author: User

1. Redis storage mechanism

Redis storage mechanisms are divided into two types: Snapshot and AOF. Regardless of the Mechanism, Redis stores data in the memory.

How Snapshot works: It stores data in the memory first, and then triggers a DUMP operation when the data reaches a certain threshold, write the changed data to the data file (RDB file) at one time ).

AOF Working principle: the data is first stored in memory, but during storage, the fsync is called to complete the log record of this write operation, this Log Exposure file is actually a text file based on the Redis network interaction protocol. AOF calling fsync does not mean that all of them are non-congested. In some systems, fsync may block the process. In this case, you can modify the configuration, but do not modify it by default. The most critical configuration of AOF is the flat rate of append log files by calling fsync. There are two preset frequencies. always are added for each record, and everysecond is added once per second. The two configurations have their own advantages and are analyzed later. Because the log append method is used to persist the data, the concept of the second log is introduced: rewrite. The origin of the second log is introduced later.

Comparison of storage mode performance and security:

1. Performance: the performance of the Snapshot method is significantly higher than that of the AOF method, for two reasons:

  • Data is stored in binary mode. The data file size is small and the loading speed is fast.
  • The storage is stored according to the configured save policy. Each time a lot of data is aggregated for batch storage, the write efficiency is very good, while AOF generally works in real-time storage or quasi-real-time mode. The storage frequency is relatively high, but the efficiency is low.

2. Data Security: AOL data security is higher than Snapshot storage, because:

  • Snapshot storage is based on the idea of accumulative batch storage. That is to say, when the accumulated data is allowed, the write efficiency will be higher, but the accumulation of data is completed by time, if the data is not written to RDB for a long time, but Redis crashes, the data that has not been written cannot be recovered, but the AOF method is the opposite, based on the storage frequency policy configured by AOF, the minimum data loss and high data recovery capabilities can be achieved.

After talking about performance and security, we have to mention the Rewrite function in Redis. AOF storage works by logging, therefore, thousands of data Inserts will inevitably lead to the expansion of log files. Redis will trigger the Rewrite operation according to the configuration, the so-called Rewrite is to re-write all the data in the log file to another new log file, but the difference is that for the Key operations in the old log file, only the operation record of the final value is retained to the log file, thus reducing the size of the log file. Note the following two configurations:

Auto-aof-rewrite-percentage 100 (Rewrite is triggered when the size of the currently written log file accounts for a certain percentage of the initial log file size)
Auto-aof-rewrite-min-size 64 mb (the minimum write data for this Rewrite operation is good)

Both conditions must be met.

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.