In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "the persistence mechanism of Redis is RDB or AOF". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "RDB or AOF" for the persistence mechanism of Redis.
RDB1. What is RDB?
RDB: at regular intervals, the data in memory is written to a temporary file on disk as a snapshot, and when restored, the snapshot file is read into memory. If there is a downtime and reboot, then there will certainly be no data in memory, so when redis is started again, it will be restored.
two。 Backup and recovery
Memory backup-- > temporary disk files
Temporary files-- > restore to memory
3. Advantages and disadvantages of RDB
advantage
Backup at regular intervals, full backup
Disaster preparedness is simple and can be transmitted remotely.
When the child process is backed up, the main process will not have any io operations (no write modification or deletion) to ensure the integrity of the backup data.
Compared with AOF, it can restart and restore quickly when there are larger files.
Inferior position
The failure is that it is possible to lose the last backup data.
The memory ratio of the child process will be exactly the same as that of the parent process, for example, it will cause CPU burden
Because scheduled full backup is a heavyweight operation, it cannot be handled for real-time backup.
4. Configuration of RDB
Save location, which can be customized in redis.conf:
/ user/local/redis/working/dump.rdb
Preservation mechanism:
Save 900 1save 300 10save 60 10000save 10 3 * if 1 cache update, backup in 15 minutes * if 10 cache updates, backup in 5 minutes * if 10000 cache updates, backup in 1 minute
Stop-writes-on-bgsave-error
Yes: if an error occurs in the save process, stop the write operation
No: may cause data inconsistency
Rdbcompression
Yes: turn on rdb compression mode
No: turn it off, it will save cpu loss, but the file will be large, the reason is the same as nginx
Rdbchecksum
Yes: use CRC64 algorithm to check the data of rdb, resulting in 10% performance loss
No: no check
Summary
RDB is suitable for the recovery of large amounts of data, but data integrity and consistency may be insufficient.
Characteristics of AOFAOF
Record the write operations requested by the user in the form of a log. Read operations are not recorded because write operations are stored.
The file is in the form of an addition rather than a modification.
Redis's aof recovery is actually a write operation that reads the appended file from beginning to end.
advantage
AOF is more durable and can be backed up in seconds, and if a problem occurs, only the last second of data will be lost, greatly increasing reliability and data integrity. So AOF can be backed up once a second, using fsync operations.
Append as log log. If the disk is full, the redis-check-aof tool will be executed.
Redis can automatically rewrite aof in the background when the data is too large. When redis continues to append the log to the old file, rewriting is also very safe and does not affect the read and write operations of the client.
All the writes contained in the AOF log will make it easier for redis to parse and recover.
Inferior position
Same data, same data, AOF is bigger than RDB.
For different synchronization mechanisms, AOF is slower than RDB because AOF backs up and writes every second, which is slightly lower than RDB. There is nothing wrong with backing up fsync per second, but if the client makes a backup fsync per write, then the performance of redis will degrade.
AOF has experienced bug, that is, when the data is recovered, the data is incomplete, which makes AOF more fragile and prone to bug, because AOF is not as simple as RDB, but in order to prevent the generation of bug, AOF will not reconstruct according to the old instructions, but refactoring according to the data instructions that exist in the cache at that time, which makes it more robust and reliable.
The configuration of AOF `# AOF is off by default, and yes can enable the file name of appendonly no# AOF: appendfilename "appendonly.aof" # no: out of sync # everysec: backup per second, recommended # always: every operation will be backed up, safe and complete, but slow performance is poor when appendfsync everysec# rewrites, whether to synchronize, no can ensure data security no-appendfsync-on-rewrite no# rewriting mechanism: avoid files getting bigger and bigger Automatically optimizing the compression instruction will fork a new process to complete the rewrite action, and the memory data in the new process will be rewritten, and the old aof file will not be read and used. Similar to rdb#, the current AOF file size is 100% of the last AOF size and the file size reaches 64m. If you meet both, will you trigger the rewriting auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mb` to use RDB or AOF?
If you can accept cache loss for a while, you can use RDB
If you compare care with real-time data, use AOF
Using the combination of RDB and AOF for persistence, RDB for cold backup, you can restore different versions in different periods, and AOF for hot backup to ensure that the data will only be lost for 1 second. When AOF is damaged and unavailable, then use RDB to restore, so that the two can be combined. In other words, Redis recovery will load AOF first, and then load RDB if there is a problem with AOF, so as to achieve the purpose of hot and cold backup.
Thank you for reading, the above is the content of "RDB or AOF for the persistence mechanism of Redis". After the study of this article, I believe you have a deeper understanding of whether the persistence mechanism of Redis uses RDB or AOF, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.