Redis2.0+在内存用尽时会做何处理 ?
它是如何决定哪些数据该被移除,哪些被维持在内存的?
希望有这方面经验的大牛帮帮忙。
如果你打开虚拟内存功能,当内存用尽时, Redis就会把那些不经常使用的数据存储到磁盘。
如果Redis里的虚拟内存被禁了,他就会用上操作系统的虚拟内存(交换内存),同时性能急剧下降。
你可以配置maxmemory参数,来避免Redis默认再分配更多的内存。
在较新版本的Redis配置文件中使用了特别的设置选项,当我需要回收内存的时候。
有5种选项规则:
参考文档:
http://antirez.com/post/redis-as-LRU-cache.html
http://eli.thegreenplace.net/2009/10/30/handling-out-of-memory-conditions-in-c/
原文中写得很清楚:
Another way to use Redis as a cache is the�maxmemory�directive, a feature that allows specifying a maximum amount of memory to use. When new data is added to the server, and the memory limit was already reached, the server will remove some old data deleting a�volatile key, that is, a key with an EXPIRE (a timeout) set, even if the key is still far from expiring automatically.
在Redis服务器OOM的情况下,一旦有新的数据需要存储,LRU机制将会被启用,老的数据将会被删除,而这个删除的算法是什么,则可以在配置文件中设置:
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don’t expire at all, just return an error on write operations
有话要说