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

AOF of Redis persistence

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Background: shortcomings of RDB

1. Time consuming and performance consuming

Time-consuming to generate snapshot files and time-consuming to load snapshot files

Form child process network overhead

Write file disk Imax O overhead

two。 Uncontrollable, lost data

The data of the last operation of the last snapshot is lost.

I. Workflow

Redis write command-- > aof buffer-- > aof file

Note that the frequency at which data from the aof buffer is synchronized to disk d is determined by the aof policy

II. Three strategies of AOF

1.Always is always

Each instruction is written in real time

There will be no data loss, disk Imaco overhead.

2.Every second per second

System default policy

Write once per minute

One second of data may be lost.

3.No system automatic

Uncontrollable

3. AOF rewriting

Over time, aof files become larger and larger. It lowers disk performance and slows down data recovery.

Objective: 1. Reduce disk occupancy; 2. Speed up the recovery.

Rewrite operation

In method 1, the client sends the instruction bgrewriteof manually

The server fork child process, which plasticizes the data in memory and then writes it to the existing aof file.

Method 2, trigger through the configuration file

File growth rate

Auto-aof-rewrite-percentage 100

Minimum file size

Auto-aof-rewrite-min-size 64mb

4. AOF experiment

1.redis write operation

27.0.1 set hello javaOK127.0.0.1:6379 > set hello worldOK127.0.0.1:6379 > set hello phpOK127.0.0.1:6379 > set hello javaOK127.0.0.1:6379 > set hello jackOK127.0.0.1:6379 > set zhang sanOK127.0.0.1:6379 > set li siOK127.0.0.1:6379 > set li xiaolongOK

The above operation overrides two key of hello,li multiple times.

two。 View aof log files

$sudo cat-b / var/lib/redis/appendonly.aof 1 REDIS0009 "redis-ver5.0.3" 2 redis-bits @ "ctime"] used-mem "aof-preamble"$e"Q" * 2 3 $6 4 SELECT 5 $16 0 7 * 3 8 $3 9 set 10 $5 11 hello 12 $5 13 world 14 * 3 15 $3 16 set 17 $5 18 Hello 19 $3 20 php 21 * 3 22 $3 23 set 24 $5 25 hello 26 $4 27 java 28 * 3 29 $3 30 set 31 $5 32 hello 33 $4 34 jack 35 * 3 36 $3 37 set 38 $5 39 zhang 40 $3 41 san 42 * 3 43 $3 44 set 45 $2 46 li 47 $2 48 si 49 * 3 50 $3 51 set 52 $2 53 li 54 $8 55 xiaolong

3. Rewrite aof

127.0.0.1 purl 6379 > bgrewriteaofBackground append only file rewriting started

4. View the rewritten aof log file

Whqlkj@whqlkj:~$ sudo cat-b / var/lib/redis/appendonly.aof 1 REDIS0009 "redis-ver5.0.3"2 redis-bits" @ "ctime"used-mem"aof-preamble"zhangsanlxiaolonghellojack" X "-"

5. Comparison between RDB and AOF

Comparison link RDBAOF start priority low high data recovery speed file size (rdb binary compressed file) large (rewritten log file) data security rdb lost data (may lose data after the last save/bgsave snapshot) aof decides according to policy (see three synchronization strategies for details) operation heavyweight (rdb snapshot) light (aof append log)

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

Database

Wechat

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

12
Report