我使用Redis 2.6.14和aof on。aof文件的大小在重写后变为0M,我无法理解这一点。帮帮忙,拜托。以下是日志:
# 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我认为"AOF重写:0MB内存使用的拷贝上写“是关键,谁来解释呢?
我用这种方式得到了答案:
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.其结论是:重写到aof的字节大小实际上不是0,而是非常小。原因是我在考试中犯了错误。
发布于 2013-08-02 15:42:20
我认为"AOF重写:0MB内存使用的拷贝上写“是关键,谁来解释呢?
它与AOF的结果大小完全无关。
Redis是一个单线程事件循环。当它必须处理一个长时间运行的作业时,例如RDB转储或AOF重写,它会分叉第二个进程来完成它。作业将与未被阻塞的Redis事件循环并行运行。这种机制利用了操作系统的虚拟内存子系统提供的即插即用功能.
当Redis分叉时,内存页将由两个进程共享。但是在作业运行时,Redis仍然可以修改这些内存页面(插入、更新、删除操作)。这些操作将被操作系统捕获,只有在修改页面时,页面才会在惰性模式下被复制。
结果是,在运行后台作业时,Redis可以或多或少地消耗内存。如果大量的写入操作发生,那么更多的内存将被复制到写入机制中消耗。
"AOF重写: xxx MB的内存被复制上写“行只是提供了一个计算的复制上写内存开销。理想情况下,应该是0(这意味着没有重复页面)。如果你在后台操作期间开始写很多东西,它就会增加。在最坏的情况下(不太可能),它可以接近Redis使用的总内存。
https://stackoverflow.com/questions/17985058
复制相似问题