2013-08-01 20 views
1

我在aof上使用Redis 2.6.14。重寫後aof文件的大小變爲0M,我無法理解這一點。給我一些幫助,PLZ。下面是日誌:爲什麼redis 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重寫:0 MB的內存寫入時複製使用」的關鍵是,誰將會解釋呢?


我得到了這樣的答案:

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,但非常小。原因是我的測試程序錯誤。

回答

3

我覺得「AOF重寫:0 MB的內存寫入時複製使用」的關鍵是,誰將會解釋呢?

它與AOF的結果大小完全無關。

Redis是一個單線程事件循環。當它必須處理一個長時間運行的作業時,如RDB轉儲或AOF重寫,它會讓第二個進程執行它。該作業將與未被阻止的Redis事件循環並行運行。該機制利用了操作系統虛擬內存子系統提供的寫時複製功能。

當Redis分叉時,內存頁面將被兩個進程共享。但是在作業運行時,Redis仍然可以修改這些內存頁面(插入,更新,刪除操作)。這些操作將被操作系統捕獲,只有在修改後頁面纔會以懶惰模式複製。

結果是,運行後臺作業時,Redis會消耗更多或更少的內存。如果發生大量寫入操作,則寫入時複製機制將消耗更多內存。

「寫入時複製使用的AOF重寫:xxx MB內存」行僅提供了對寫入時複製內存開銷的評估。理想情況下,它應該是0(意味着沒有頁面被重複)。如果你在後臺操作過程中開始寫很多,它會增加。在最壞的情況下(不太可能),它可能接近Redis使用的總內存。

+0

我認爲它應該是重寫時所有數據的大小。 – zhmt

+0

不,它只是表示COW複製數據的大小(通常遠離所有數據的大小)。 –

+0

我明白了,謝謝。 – zhmt

相關問題