Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the reasonable persistence strategies for Redis configuration

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about what Redis has to do with its persistence strategy. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Rational allocation of persistence strategy

Redis supports two persistence strategies, RDB and AOF.

RDB generates data snapshots in binary format through the fork child process.

AOF is an incremental log, text format, and usually large. The log is rewritten through AOF rewrite to save space.

In addition to manually executing the "BGREWRITEAOF" command, the following four points also trigger AOF rewriting

Execute the "config set appendonly yes" command

The AOF file size ratio exceeds the threshold, "auto-aof-rewrite-percentage"

The absolute size of the AOF file exceeds the threshold, "auto-aof-rewrite-min-size"

Master-slave copy completes RDB loading

Both RDB and AOF trigger execution in the main thread. Although the implementation is specific, it will be handed over to the backstage child process through fork. However, the fork operation will copy the process data structure, page table, and so on, which will affect the performance when the instance memory is large.

AOF supports the following three strategies.

Appendfsync no: it is up to the operating system to decide when to execute fsync. For Linux, the fsync is usually executed every 30 seconds, brushing the data from the buffer to disk. If the Redis qps is too high or big key is written, it may cause the buffer to be full, thus triggering the fsync frequently.

Appendfsync everysec: fsync is executed once per second.

Appendfsync always: fsync will be called once for each "write", which has a great impact on performance.

Both AOF and RDB put high pressure on disk IO. Where AOF rewrite traverses all the data in the Redis hash table and writes to disk. It will have a certain impact on performance.

Online business Redis is usually highly available. If it is not sensitive to cached data loss. Consider shutting down RDB and AOF to improve performance.

If it cannot be closed, here are some suggestions:

RDB chooses business trough, usually in the early hours of the morning. Keep the memory of a single instance no more than 32 GB. Too much memory can cause fork to take more time.

AOF choose appendfsync no or appendfsync everysec.

The AOF auto-aof-rewrite-min-size configuration is larger, such as 2G. Avoid triggering rewrite frequently.

AOF can be opened only in the slave node to reduce the pressure on the master node.

According to local tests, if AOF is not enabled, write performance can be improved by about 20%.

Thank you for reading! This is the end of this article on "what is the reasonable configuration of persistence strategy for Redis?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report