MaxMemory Settings for Redis

Source: Internet
Author: User

The maxmemory parameter of Redis is used to control the maximum memory capacity that Redis can use. If the value of MaxMemory is exceeded, the elimination policy is used to process the keys in the Expaire dictionary.

About Redis's elimination strategy, a lot of articles are described, do not explain.

With regard to MaxMemory settings, if the Redis scenario is used as DB, do not set this option because the DB is not tolerant of data loss.

If used as a cache, you can enable this option (in fact, since the elimination strategy, it is the cache ...) )

However, in a clustered environment (especially with multiple slavers cases), the value of maxmeomory is not the memory used by the actual redis, and this option value does not include the output buffer of slaver.

The earlier version of Redis had a bug in which, in the case of multiple slaver, the MaxMemory value was set and the elimination policy was set, which caused the data on master to be gradually erased.

Mr. Antirez the cause of the problem:

The issue happens for the following Reason:redis reached the configured limit, so it tries to expire keys. Evicting keys turns into explicit DELs sent to slaves, since Masters control the eviction of slaves for well known reasons . But this if there is enough slaves, emitting the protocol in the output buffers would actually take more memory than t He amount freed removing keys ... So the key eviction process starts to enter into an infinite loop. Up-to-a given point the fact that there was a static buffer part in the output queue of every client (including slaves) MIT iGATE the certain conditions, but once Redis can ' t use the output buffer but must use the queue of objects the Infinit E loop is triggered.

Simply put, delete the expiration key, need to produce del command sent to Slaver, if slaver enough, output buffer will occupy enough memory, cause more keys to expire, so back and forth, into the wireless loop.

There are a number of solutions, such as output buffer, which does not count toward MaxMemory.

As a result, the following is stated in the configuration instructions in version 3.0:

# warning:if You has slaves attached to a instance with MaxMemory on,# the size of the output buffers needed to feed th E Slaves is subtracted# from the used memory count, so this network Problems/resyncs will# not trigger a loop where key  S was evicted, and in turn the output# buffer of slaves was full with DELs of keys evicted triggering the deletion# of more Keys, and so forth until the database was completely emptied.## in short ... if you had slaves attached it is suggested th At your set a lower# limit for maxmemory So, there is some free RAM on the system for slave# output buffers s not needed if the policy is ' noeviction '). # maxmemory <bytes>

Thus, if there is a slaver case, it is advisable to lower the maxmemory appropriately, to allow a certain amount of free space in the output buffer is reasonable.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MaxMemory Settings for Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.