我有一個Redis實例充當Logstash的隊列和Sensu的數據庫,因此Logstash能夠處理以提交給Redis的速度記錄日誌,Sensu只存儲最新的測量結果。但是,當我執行檢查Redis的內存使用量,是說:Redis RDB方式比內存使用率更小(203KB)(716MB)
[email protected]:/data# redis-cli info | grep memory used_memory:751751344 used_memory_human:716.93M used_memory_rss:774729728 used_memory_peak:754163560 used_memory_peak_human:719.23M used_memory_lua:154624
但是,當我檢查dump.rdb
文件的大小,它說:
[email protected]:/data# ls -lah total 212K drwxr-xr-x 2 redis redis 4.0K Apr 24 08:22 . drwxr-xr-x 49 root root 4.0K Apr 21 06:07 .. -rw-r--r-- 1 redis redis 203K Apr 24 08:22 dump.rdb
Logstash似乎工作正常;日誌正在流入Kibana,度量進入Grafana。
當我運行rdb -c memory dump.rdb
我得到了很多使用很少的內存按鍵,只有topbeat
鍵(我用topbeat收集指標)使用顯著內存:
database,type,key,size_in_bytes,encoding,num_elements,len_largest_element 0,list,"topbeat",797811,linkedlist,1686,986
然而,797811個字節仍然只有779 KB。
那麼,爲什麼Redis仍然佔用了所有的內存?它的內存使用量在過去的2200分鐘內以每分鐘300KB的速度穩步增長。
這裏一些日誌:
1:M 24 Apr 08:22:07.312 * 10000 changes in 60 seconds. Saving... 1:M 24 Apr 08:22:07.333 * Background saving started by pid 5648 5648:C 24 Apr 08:22:07.346 * DB saved on disk 5648:C 24 Apr 08:22:07.362 * RDB: 1 MB of memory used by copy-on-write 1:M 24 Apr 08:22:07.449 * Background saving terminated with success 1:M 24 Apr 08:25:07.403 * 10000 changes in 60 seconds. Saving... 1:M 24 Apr 08:25:07.427 * Background saving started by pid 5657 5657:C 24 Apr 08:25:07.462 * DB saved on disk 5657:C 24 Apr 08:25:07.473 * RDB: 1 MB of memory used by copy-on-write 1:M 24 Apr 08:25:07.527 * Background saving terminated with success 1:M 24 Apr 08:29:07.375 * 10000 changes in 60 seconds. Saving... 1:M 24 Apr 08:29:07.391 * Background saving started by pid 5660 5660:C 24 Apr 08:29:07.419 * DB saved on disk 5660:C 24 Apr 08:29:07.433 * RDB: 1 MB of memory used by copy-on-write 1:M 24 Apr 08:29:07.492 * Background saving terminated with success 1:M 24 Apr 08:33:07.372 * 10000 changes in 60 seconds. Saving... 1:M 24 Apr 08:33:07.396 * Background saving started by pid 5661 5661:C 24 Apr 08:33:07.423 * DB saved on disk 5661:C 24 Apr 08:33:07.435 * RDB: 2 MB of memory used by copy-on-write 1:M 24 Apr 08:33:07.496 * Background saving terminated with success
感謝您的解釋。但是,您有建議如何防止內存使用量的增長?如果這種方式持續幾天,我的虛擬機上就不會有任何可用的內存了。 – Peter
@Peter我懷疑它是與內部散列表類似的algorythm在將要使用之前保留內存的東西。 –
@Peter請參閱http://redis.io/topics/config上的最大內存部分 –