美文网首页
REDIS----配置文件----LAZY FREEING

REDIS----配置文件----LAZY FREEING

作者: JuMinggniMuJ | 来源:发表于2020-06-06 20:28 被阅读0次

LAZY FREEING部分:

1.DEL:
# Redis has two primitives to delete keys. One is called DEL and is a blocking
# deletion of the object. It means that the server stops processing new commands
# in order to reclaim all the memory associated with an object in a synchronous
# way. If the key deleted is associated with a small object, the time needed
# in order to execute the DEL command is very small and comparable to most other
# O(1) or O(log_N) commands in Redis. However if the key is associated with an
# aggregated value containing millions of elements, the server can block for
# a long time (even seconds) in order to complete the operation.

Redis有两个命令用于删除键。一个称为DEL,是对对象的阻塞删除。这意味着服务器停止处理新命令,以便以同步方式回收与对象关联的所有内存。如果删除的键与一个小对象相关联,则执行DEL命令所需的时间非常短,与Redis中的大多数其他O(1)或O(log_N)命令相当。但是,如果key与包含数百万个元素的聚合值关联,则服务器可以阻塞很长时间(甚至几秒钟)以完成操作。

2.UNLINK:
# For the above reasons Redis also offers non blocking deletion primitives
# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and
# FLUSHDB commands, in order to reclaim memory in background. Those commands
# are executed in constant time. Another thread will incrementally free the
# object in the background as fast as possible.

出于上述原因,Redis还提供了UNLINK(non-blocking DEL)等非阻塞删除命令以及FLUSHALL和FLUSHDB命令的异步选项,以便在后台回收内存。这些命令在固定时间内执行。另一个线程将尽可能在后台释放对象。

3.设置独立删除情况:
# DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.
# It's up to the design of the application to understand when it is a good
# idea to use one or the other. However the Redis server sometimes has to
# delete keys or flush the whole database as a side effect of other operations.
# Specifically Redis deletes objects independently of a user call in the
# following scenarios:
#
# 1) On eviction, because of the maxmemory and maxmemory policy configurations,
#    in order to make room for new data, without going over the specified
#    memory limit.
# 2) Because of expire: when a key with an associated time to live (see the
#    EXPIRE command) must be deleted from memory.
# 3) Because of a side effect of a command that stores data on a key that may
#    already exist. For example the RENAME command may delete the old key
#    content when it is replaced with another one. Similarly SUNIONSTORE
#    or SORT with STORE option may delete existing keys. The SET command
#    itself removes any old content of the specified key in order to replace
#    it with the specified string.
# 4) During replication, when a replica performs a full resynchronization with
#    its master, the content of the whole database is removed in order to
#    load the RDB file just transferred.

FLUSHALL和FLUSHDB的DEL、UNLINK和ASYNC选项由用户控制。这取决于应用程序的设计,所以了解何时使用一个或另一个是一个好主意。然而,Redis服务器有时不得不删除keys或刷新整个数据库,这是其他操作的副作用。具体来说,在以下情况下,Redis独立于用户调用删除对象:
1.在逐出时,由于maxmemory和maxmemory策略配置,为了在不超过指定内存限制的情况下为新数据腾出空间
2.因为过期:必须从内存中删除具有相关生存时间的key
3.因为将数据存储在可能已经存在的keys上的命令的副作用。例如,当旧的keys内容被另一个keys内容替换时,RENAME命令可能会删除它。类似地,SUNIONSTORE或SORT with STORE选项可以删除现有keys。SET命令本身删除指定键的任何旧内容,以便用指定字符串替换它
4.在复制过程中,当复制副本与其主服务器执行完全重新同步时,将删除整个数据库的内容,以便加载刚刚传输的RDB文件

4.设置:
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

1.因为此场景开启lazy free, 可能使用淘汰键的内存释放不及时,导致redis内存超用,超过maxmemory的限制不建议开启
2.针对设置有TTL的键,达到过期后,被redis清理删除时是否采用lazy free机制
3.如rename命令,当目标键已存在, redis会先删除目标键,如果这些目标键是一个big key, 那就会引入阻塞删除的性能问题。 此参数设置就是解决这类问题建议开启
4.如果内存变动不大,建议可开启。可减少全量同步耗时,从而减少主库因输出缓冲区爆涨引起的内存使用增长

相关文章

网友评论

      本文标题:REDIS----配置文件----LAZY FREEING

      本文链接:https://www.haomeiwen.com/subject/mxhizhtx.html