This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24125|Reply: 2

[Redis] Redis Persistence Difference Between RDB and AOF

[Copy link]
Posted on 2/4/2021 1:47:27 PM | | | |
Redis windows 64-bit download, official download address
https://www.itsvse.com/thread-2576-1-1.html

Redis has three ways to start
https://www.itsvse.com/thread-4008-1-1.html

The difference between save and bgsave in redis
https://www.itsvse.com/thread-4010-1-1.html

CentOS 7 installation Redis 5.0.3 tutorial
https://www.itsvse.com/thread-7201-1-1.html


1. Preface

Recently, Redis has been used as a cache in the project to facilitate data sharing among multiple business processes. Since Redis data is stored in memory, if persistence is not configured, all data will be lost after redis restart, so you need to enable the persistence function of redis to save the data to the disk, and when redis is restarted, you can recover data from the disk. Redis provides two ways to persist, RDB persistence (the principle is to dump Reids' database records in memory to RDB persistence on disk) and the other is AOF persistence (the principle is to write Reids' operation logs to a file in the form of an appendix). So what is the difference between these two persistence methods, and how to choose to change it? Most of the things I read on the Internet introduce how to configure and use these two methods, but there is no introduction to the difference between the two, and in what application scenarios to use.


2. The difference between the two

RDB persistence refers to writing a snapshot of the dataset in memory to disk within a specified time interval, and the actual operation process is to fork a subprocess, first write the dataset to a temporary file, and then replace the previous file after the writing is successful, and store it with binary compression.



AOF persistence records every write and delete operation processed by the server in the form of a log, and the query operation will not be recorded, but will be recorded in text, and you can open the file to see the detailed operation record.



3. Advantages and disadvantages of the two

What are the advantages of RDB?

1). Once this is used, then your entire Redis database will contain only one file, which is perfect for file backups. For example, you may want to archive the last 24 hours every hour, and also archive the last 30 days every day. With such a backup strategy, we can easily recover in the event of a catastrophic failure of the system.

2). RDB is a very good choice for disaster recovery. Because we can easily compress a single file and transfer it to another storage medium.

3). Maximize performance. For the Redis service process, the only thing it needs to do when starting persistence is to fork out the child processes, and then the child processes will complete these persistence tasks, which can greatly avoid the service process performing IO operations.

4). Compared with the AOF mechanism, if the dataset is large, the startup efficiency of RDB will be higher.

What are the disadvantages of RDB?

1). If you want to ensure high availability of data, i.e. avoid data loss to the greatest extent, then RDB will not be a good choice. Because once the system goes down before the scheduled persistence, the data that was previously written to disk will be lost.

2). Since RDB assists in data persistence through fork subprocesses, if the data set is large, it may cause the entire server to stop service for hundreds of milliseconds, or even 1 second.

What are the advantages of AOF?

1). This mechanism can bring greater data security, i.e., data persistence. There are 3 synchronization strategies provided in Redis, namely synchronization per second, synchronization per modification, and desynchronization. In fact, the synchronization per second is also done asynchronously, and its efficiency is also very high, the difference is that once the system goes down, then the modified data will be lost within this second. And every time a modification is synchronized, we can think of it as synchronization persistence, that is, every data change that occurs is immediately recorded to disk. It is foreseeable that this method is the least efficient. As for no synchronization, there is no need to say more, I think everyone can understand it correctly.

2). Since the mechanism adopts the append mode for writing log files, even if there is a downtime during the writing process, the content already existing in the log file will not be destroyed. However, if we only write half of the data and the system crashes this time, don't worry, we can use the redis-check-aof tool to help us solve the data consistency problem before the next start of Redis.

3). If the log is too large, Redis can automatically enable the rewrite mechanism. That is, Redis continuously writes the modification data to the old disk file in the append mode, and Redis will also create a new file to record which modification commands are executed during this period. Therefore, data security can be better guaranteed when switching between rewrites.

4). AOF contains a clear, easy-to-understand log file that records all modifications. In fact, we can also complete the reconstruction of the data through this file.

What are the disadvantages of OV?

1). For the same number of datasets, OF files are usually larger than RDB files. RDB recovers large datasets faster than AOF.

2). Depending on the synchronization strategy, AOF tends to be slower than RDB in terms of running efficiency. In short, the efficiency of the synchronization policy per second is relatively high, and the efficiency of the synchronous disabling policy is as efficient as that of RDB.

The criteria for choosing the two are whether the system is willing to sacrifice some performance in exchange for higher cache consistency (AOF), or whether it is willing to not enable backups in exchange for higher performance when writing operations are frequent, and then do backups (RDB) when running Save manually. rdb has a more final consistent meaning. However, the production environment is actually more of a combination of the two.


4. Common configurations

RDB persistence configuration

Redis dumps a snapshot of the dataset into the dump.rdb file. In addition, we can also modify the frequency of Redis server dump snapshots through the configuration file, after opening the 6379.conf file, we search for save, and we can see the following configuration information:



AOF persistent configuration

There are three ways to synchronize in the Redis profile, they are:



Complete configuration:



A new file "appendonly.aof" will be created under the test directory, as follows:





Previous:DataTables implements table export Excel, CSV, and printing
Next:SQL Server sets the transaction isolation level
 Landlord| Posted on 2/8/2021 11:45:25 AM |
Redis modifies the default port number and sets the access password
https://www.itsvse.com/thread-2577-1-1.html
Posted on 9/22/2021 8:26:16 PM |
Learn to learn...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com