zhmt
zhmt

Reputation: 23

why redis aof rewrite 0M to disk?

I am using Redis 2.6.14 with aof on. The size of aof file becomes to 0M after rewriting, I cant understand this. Give me some help,plz. Below is the log:

 # Server started, Redis version 2.6.14
 * The server is now ready to accept connections on port 7379
 * Starting automatic rewriting of AOF on 2098226700% growth
 * Background append only file rewriting started by pid 7961
 * SYNC append only file rewrite performed
 * AOF rewrite: 0 MB of memory used by copy-on-write
 * Background AOF rewrite terminated with success
 * Parent diff successfully flushed to the rewritten AOF     (94778 bytes)
 * Background AOF rewrite finished successfully

I think "AOF rewrite: 0 MB of memory used by copy-on-write" is the key, who will explain it?


I got the answer in this way:

1.edit the redis.conf, set the loglevel to debug.
2.I found that the keys is only 32, so it is the problem of my test program.
3.I modified the test program, make keys unique. When the program runs again, the keys in reids increase rapidly, and the aof file increase too.
4.when the rewrite is triggered, write 2M bytes into aof file instead of 0M.

The conclusion is : the size of bytes rewritten to aof is not really 0, but very small. The reason is my mistake in test program.

Upvotes: 1

Views: 3297

Answers (1)

Didier Spezia
Didier Spezia

Reputation: 73226

I think "AOF rewrite: 0 MB of memory used by copy-on-write" is the key, who will explain it?

It is totally unrelated to the resulting size of the AOF.

Redis is a single-threaded event loop. When it has to process a long running job, such as a RDB dump or an AOF rewrite, it forks a second process to do it. The job will run in parallel with the Redis event loop, which is not blocked. This mechanism leverages the copy-on-write facility provided by the virtual memory subsystem of the OS.

When Redis forks, the memory pages will be shared by the two processes. But while the job is running, Redis can still modify these memory pages (insert, update, delete operations). These operations will be caught by the OS, and the pages will be duplicated in lazy mode, only when they are modified.

The consequence is Redis can consume more or less memory when running a background job. If a lot of write operations occur, then more memory will be consumed by the copy-on-write mechanism.

The "AOF rewrite: xxx MB of memory used by copy-on-write" line just provides an evaluation of the copy-on-write memory overhead. Ideally, it should be 0 (meaning that no page was duplicated). If you start writing a lot during the background operation, it will increase. In the worst case (unlikely), it can be close to the total memory used by Redis.

Upvotes: 3

Related Questions