Redis 快速填满内存,运行 --bigkeys 将其释放 [英] Redis filling up memory fast, running --bigkeys free it up

查看:139
本文介绍了Redis 快速填满内存,运行 --bigkeys 将其释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个月前,Redis 突然开始快速填满服务器内存.为了调试问题,我们运行了 redis-cli --bigkeys,令我们惊讶的是,所有使用的内存都被释放了.

A month ago, out of the blue, Redis started to fill up the server memory fast. In order to debug the problem we have run redis-cli --bigkeys and for our surprise all the used memory was freed.

我们有一个由 6 个节点组成的集群,分别是 3 个主和 3 个从,每个主数据库大约 15GB.每个节点都存储在一个专用的盒子中,每个盒子有 64GB.Redis 每天两次填充 64GB 的整个内存.我们有一个 cron 每天运行两次 redis-cli --bigkeys 以释放使用的内存.

We have a cluster of 6 nodes, being 3 masters and 3 slaves, each of the masters databases are around 15GB. Each of the nodes are stored in a dedicated box with 64GB each. Redis is filling the entire memory of 64GB twice a day. We have a cron running redis-cli --bigkeys twice a day to free up the used memory.

可能是什么原因?

谢谢.

推荐答案

听起来你会收到 OOM command not allowed 错误,除非你运行 redis-cli --bigkeys一天两次.

Sounds like you are getting OOM command not allowed errors unless you run redis-cli --bigkeys twice a day.

如果是这种情况,您可能有许多和/或带有 EXPIRE 的大键,并且不断添加.从内存中删除过期的密钥:

If that's the case, you probably have many and/or big keys with EXPIRE, being added constantly. Expired keys are removed from memory:

  • 被动:当您尝试访问它并且发现密钥超时时.这就是 redis-cli --bigkeys 为您提供的帮助,它强制被动删除所有键空间.
  • 主动:每 100 毫秒,它会尝试从内存中删除过期的键 at随机,每个周期永远不会超过 1 毫秒,直到它估计不到 25% 的过期密钥仍然存在.逻辑不是那么简单,请参阅 activeExpireCycle.
  • Passively: when you try to access it and the key is found to be timed out. This is how redis-cli --bigkeys is helping you, it forces a passive removal across all the keyspace.
  • Actively: every 100 ms, it tries to remove from memory expired keys at random, never investing more than 1 ms per cycle at it, until it estimates that less than 25% of expired keys remain. The logic is not that trivial, see activeExpireCycle.

因此,在您的情况下,活动过期无法赶上所有要点.

So it all points that the active expire is not able to catch up in your case.

根据您的评论,maxmemory=0maxmemory-policy=noeviction.您可能需要考虑将 maxmemory 值和 maxmemory-policy=noeviction 设置为 volatile-ttl(删除最接近到期​​时间的密钥).

From your comment, maxmemory=0 and maxmemory-policy=noeviction. You may want to consider setting a maxmemory value, and maxmemory-policy=noeviction to volatile-ttl (remove the key with the nearest expire time).

这是做什么的,每当写入命令发现您超过 maxmemory 时,它会根据策略尝试为新密钥释放空间.volatile-ttl 策略将首先驱逐任何剩余的过期密钥.参见 evict.c.

What this does, whenever a write commands finds you are over maxmemory, it will try to free space for the new key, based on the policy. The volatile-ttl policy would evict first any expired keys remaining. See evict.c.

您也可以增加后台任务的频率,以更频繁地清除过期密钥,请参阅 redis.conf.你可以加倍到 20.

You may also increase the frequency of the background tasks, to purge expired keys more often, see hz in redis.conf. You may double it to 20.

默认情况下,"hz" 设置为 10.提高该值将使用更多 CPURedis 是空闲的,但同时会让 Redis 响应更快有许多密钥同时到期,可能会超时处理更精确.

By default "hz" is set to 10. Raising the value will use more CPU when Redis is idle, but at the same time will make Redis more responsive when there are many keys expiring at the same time, and timeouts may be handled with more precision.

此外,activedefrag = yes 可能会有所帮助,请参阅 这里.

Also, activedefrag = yes may help, see here.

有一个新的 active-expire-effort redis.conf 设置可以让你在 active-expire 上投入更多的 CPU,但它在最新的稳定版本 (5.0.7) 中不可用).

There is a new active-expire-effort redis.conf setting that would allow you to invest more CPU in active-expire, but it is not available in the latest stable release (5.0.7).

使用 INFO memory 来了解您的 Redis 服务器内存状态.如果以上内容对您没有帮助,请使用此输出更新问题.

Use INFO memory to get a sense of your redis server memory status. Please update the question with this output if the above doesn't help you.

这篇关于Redis 快速填满内存,运行 --bigkeys 将其释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆