Redis5.0.3配置文件详解(易读白话翻译)内存管理

编程

############################## MEMORY MANAGEMENT ################################

# Set a memory usage limit to the specified amount of bytes.

# When the memory limit is reached Redis will try to remove keys

# according to the eviction policy selected (see maxmemory-policy).

# 设置Redis的工作最大内存为某一个特定的限制值。当内存使用达到限制值,根据设置的淘汰策略删除keys

#

# If Redis can"t remove keys according to the policy, or if the policy is

# set to "noeviction", Redis will start to reply with errors to commands

# that would use more memory, like SET, LPUSH, and so on, and will continue

# to reply to read-only commands like GET.

# 当Redis无法根据设置的淘汰策略删除keys时或者淘汰策略被设置为"noeviction",像set lpush等命令会收到报错,此时管理员就应该特别注意了,及时的增加内存,但是此时读命令还是可以继续正常使用的

#

# This option is usually useful when using Redis as an LRU or LFU cache, or to

# set a hard memory limit for an instance (using the "noeviction" policy).

# 如果将Redis作为一个LRU或者LFU的缓存,再或者将Redis作为hard memory limit for an instance使用时,这个选项就非常有用

#

# WARNING: If you have replicas attached to an instance with maxmemory on,

# the size of the output buffers needed to feed the replicas are subtracted

# from the used memory count, so that network problems / resyncs will

# not trigger a loop where keys are evicted, and in turn the output

# buffer of replicas is full with DELs of keys evicted triggering the deletion

# of more keys, and so forth until the database is completely emptied.

# 如果一个设置了"maxmemory"的主节点连接了一个从节点,那么用于主从复制传递命令的输出缓冲区占用的内存也在maxmemory当中,如果当内存被占满时而出现大量的删除key的操作写到缓冲区,而缓冲区又不够,又会触发删除更多的key,这样就会造成一个死循环,直到整个数据库变成空的。

# 因此

#

# In short... if you have replicas attached it is suggested that you set a lower

# limit for maxmemory so that there is some free RAM on the system for replica

# output buffers (but this is not needed if the policy is "noeviction").

# 因为used memory是可以大于maxmemory的,只不过出现这种情时会导致内存回收而触发删除KEY的操作。因此,如果在主从模式下,主节点的maxmemory在设置得足够大的情况下,还要给输出缓冲区留出一点空间来,避免出现死循环而导致数据库被清空。不要物理内存有多少就设置多少,况且还有操作系统和其他程序在运行,一般设置为3/4。

#

# maxmemory <bytes>

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory

# is reached. You can select among five behaviors:

#

# volatile-lru -> Evict using approximated LRU among the keys with an expire set.

# allkeys-lru -> Evict any key using approximated LRU.

# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.

# allkeys-lfu -> Evict any key using approximated LFU.

# volatile-random -> Remove a random key among the ones 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 evict anything, just return an error on write operations.

# 关于这几个策略的讲解百度可以找到非常好的描述,在这里就不详细描述了,篇幅也不够

# 推荐一个:https://cloud.tencent.com/developer/article/1530553 讲了原理和使用说明

#

# LRU means Least Recently Used 最近没有被使用的

# LFU means Least Frequently Used 最近使用频率最小的

#

# Both LRU, LFU and volatile-ttl are implemented using approximated randomized algorithms

# LRU LFU 和volatile-ttl使用了较接近的随机算法

#

# Note: with any of the above policies, Redis will return an error on write

# operations, when there are no suitable keys for eviction.

# 选择上面的任何一种策略,如果没有适合的KEY被淘汰,那么下面的这些写操作就会报错

#

# At the date of writing these commands are: set setnx setex append

# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd

# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby

# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby

# getset mset msetnx exec sort

#

# The default is:

# 默认设置是noeviction

#

# maxmemory-policy noeviction

# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated

# algorithms (in order to save memory), so you can tune it for speed or

# accuracy. For default Redis will check five keys and pick the one that was

# used less recently, you can change the sample size using the following

# configuration directive.

# LRU LFU TTL三种方式并不是精准的算法,这是为了提高速度和节省内存,同时达到了近似的效果。。。很妙

# 我们可以基于速度或者精准度的要求去调整采样的数据大小,"maxmemory-samples"值越大精准度越高,速度越慢,消耗的内存也越多,反之速度快,但是精准度低,内存开销少

#

# The default of 5 produces good enough results. 10 Approximates very closely

# true LRU but costs more CPU. 3 is faster but not very accurate.

# 默认值是5,如果设置为10就非常接近真正的LRU算法了,但是CPU开销也越多了。如果设置为3,速度快了,但是没那么准确

#

# maxmemory-samples 5

# Starting from Redis 5, by default a replica will ignore its maxmemory setting

# (unless it is promoted to master after a failover or manually). It means

# that the eviction of keys will be just handled by the master, sending the

# DEL commands to the replica as keys evict in the master side.

# 从Redis 5开始,从节点默认是忽略掉maxmemory设置的,除非从节点在故障转移时变成了主节点

# 正常情况下,从节点的Key淘汰是通过从主节点发送del命令过来实现的

#

# This behavior ensures that masters and replicas stay consistent, and is usually

# what you want, however if your replica is writable, or you want the replica to have

# a different memory setting, and you are sure all the writes performed to the

# replica are idempotent, then you may change this default (but be sure to understand

# what you are doing).

# "replica-ignore-maxmemory"可以保证主从的数据一致性,除非你真的知道自己把"replica-ignore-maxmemory"

# 设置为no带来的副作用,那建议你不要做着骚的操作,坑人哦

#

# Note that since the replica by default does not evict, it may end using more

# memory than the one set via maxmemory (there are certain buffers that may

# be larger on the replica, or data structures may sometimes take more memory and so

# forth). So make sure you monitor your replicas and make sure they have enough

# memory to never hit a real out-of-memory condition before the master hits

# the configured maxmemory setting.

# 由于从节点默认情况下是不主动删除KEY的,它可能比主节点消耗更多的内存(可能buffer更大,可能数据结构消耗的内存更多等等),所以要使用你的monitor实时监控你的从节点,并保证主节点达到maxmemory时间先于从节点的内存超过真正的物理内存

#

# replica-ignore-maxmemory yes

 

以上是 Redis5.0.3配置文件详解(易读白话翻译)内存管理 的全部内容, 来源链接: utcz.com/z/513255.html

回到顶部