Redis maxmemory settings, redismaxmemory

Source: Internet
Author: User

Redis maxmemory settings, redismaxmemory

The maxmemory parameter of redis is used to control the maximum memory capacity available for redis. If the value of maxmemory is exceeded, the elimination policy is used to process keys in the expaire dictionary.

Many articles have described the redis elimination policy, so I will not explain it.

For maxmemory settings, if the redis application scenario is used as a db, do not set this option, because db cannot tolerate data loss.

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

However, in a cluster environment (especially when multiple slavers exist), The maxmeomory value is not the memory used by the actual redis. This option value does not include the output buffer of slaver.

In earlier versions of apsaradb for redis, a bug occurs. When multiple server load balancers are used, maxmemory values are set and elimination policies are set. This will gradually erase the data on the master node.

Mr. antirez gave the reason for this 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 way if there are enough slaves, emitting the protocol in the output buffers will actually take more memory than the 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 is a static buffer part in the output queue of every client (including slaves) mitigate this in certain conditions, but once Redis can't use the output buffer but must use the queue of objects the infinite loop is triggered.

To put it simply, to delete the expiration key, you need to generate the del command and send it to slaver. If there are enough slaver, the output buffer will occupy enough memory, resulting in more keys to expire, it is in a wireless loop.

There are multiple solutions. For example, output buffer can be excluded from maxmemory.

Therefore, the following statements are provided in the configuration description of version 3.0:

# WARNING: If you have slaves attached to an instance with maxmemory on,# the size of the output buffers needed to feed the slaves 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 slaves is full with DELs of keys evicted triggering the deletion# of more keys, and so forth until the database is completely emptied.## In short... if you have slaves attached it is suggested that you set a lower# limit for maxmemory so that there is some free RAM on the system for slave# output buffers (but this is not needed if the policy is 'noeviction').## maxmemory <bytes>

It can be seen that if slaver is available, it is recommended that maxmemory be appropriately lowered to leave a certain amount of available space for the output buffer.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.