如何确定Redis内存泄漏? [英] How to determine Redis memory leak?

查看:770
本文介绍了如何确定Redis内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从昨天开始,我们的Redis服务器逐渐(200MB/小时)使用更多的内存,而密钥数量(330K)及其数据(132MB

Our redis servers are, since yesterday, gradually (200MB/hour) using more memory, while the amount of keys (330K) and their data (132MB redis-rdb-tools) stay about the same.

redis-cli信息输出显示6.89G已用内存?!

Output of redis-cli info shows 6.89G used memory?!

redis_version:2.4.10
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.6
process_id:3437
uptime_in_seconds:296453
uptime_in_days:3
lru_clock:1905188
used_cpu_sys:8605.03
used_cpu_user:1480.46
used_cpu_sys_children:1035.93
used_cpu_user_children:3504.93
connected_clients:404
connected_slaves:0
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
used_memory:7400076728
used_memory_human:6.89G
used_memory_rss:7186984960
used_memory_peak:7427443856
used_memory_peak_human:6.92G
mem_fragmentation_ratio:0.97
mem_allocator:jemalloc-2.2.5
loading:0
aof_enabled:0
changes_since_last_save:1672
bgsave_in_progress:0
last_save_time:1403172198
bgrewriteaof_in_progress:0
total_connections_received:3616
total_commands_processed:127741023
expired_keys:0
evicted_keys:0
keyspace_hits:18817574
keyspace_misses:8285349
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:1619791
vm_enabled:0
role:slave
master_host:***BLOCKED***
master_port:6379
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
db0:keys=372995,expires=372995
db6:keys=68399,expires=68399

当我们将(.net)客户端代码从BookSleeve 1.1.0.4更新到ServiceStack v3.9.71以准备升级到Redis 2.8时,问题就开始了.但是,还有许多其他内容已更新为,而我们的会话状态存储(也有Redis,但带有Harbor客户端)没有显示相同的症状.

The problem started when we updated our (.net) client code from BookSleeve 1.1.0.4 to ServiceStack v3.9.71 to prepare for an upgrade to Redis 2.8. But a lot of other stuff was updated to And our session state store (also redis, but with harbour client) does not show the same symptoms.

Redis的所有内存都在哪里?如何解决其用法?

Where is all that Redis memory going? How can I troubleshoot it's usage?

我刚刚重新启动了该实例,并且内存返回到350M,现在又在爬升.前10个最大的对象仍保持相同的大小,对于nr 1,范围从100K到25M.密钥数量已降至270K(之前为330K).

I just restarted this instance and memory returned to 350M and is now climbing again. The top 10 largest objects are still the same size, ranging from 100K to 25M for nr 1. The amount of keys has dropped to 270K (330K earlier).

推荐答案

以下是Redis中隐藏"内存消耗的一些来源:

Here are some sources of "hidden" memory consumption in Redis:

  • Marc已经提到了由主服务器维护的缓冲区,以供从属服务器使用.如果从属计算机落后于其主计算机(例如,因为它在较慢的机器上运行),则将在主计算机上消耗一些内存.

  • Marc already mentioned the buffers maintained by the master to feed the slave. If a slave is lagging behind its master (because it runs on a slower box for instance), then some memory will be consumed on the master.

当检测到长时间运行的命令时,Redis将它们记录在SLOWLOG区域中,该区域会占用一些内存.您可能要使用SLOWLOG LEN命令来检查此处的记录数.

when long running commands are detected, Redis logs them in the SLOWLOG area, which takes some memory. You may want to use the SLOWLOG LEN command to check the number of records you have here.

通信缓冲区也可以占用内存.据我所记得,在Redis的旧版本中(2.4已经很旧了-您应该真正升级),它是无界的,这意味着如果您在某个点上传输一个大对象,则与此客户端连接相关联的通信缓冲区将增加永不缩水.如果有很多客户偶尔处理大型物体,则可能是一种解释.如果您使用命令从Redis中检索非常大的数据(一次完成),那么它也可能是一种解释.例如,在Redis服务器上应用简单的KEYS *命令来存储数百万个密钥,将消耗大量内存.

communication buffers can also take memory. As far as I remember, with old versions of Redis (and 2.4 is quite old - you should really upgrade), it was unbounded, meaning that if you transfer a big object at a point, the communication buffer associated to this client connection will grow and never shrink. If there are many clients dealing occasionally with large objects, it could be a possible explanation. If you use commands retrieving very large data from Redis (in one shot), it can be an explanation as well. For instance, a simple KEYS * command applied on a Redis server storing millions of keys will consume a significant amount of memory.

您提到您有多达25 MB的对象.您有404个客户端连接,如果每个客户端都需要在某个时间点访问此类对象,则会消耗10 GB的内存.

You mentioned that you have objects as big as 25 MB. You have 404 client connections, if each of them needs to access such objects at a point in time, it will consume 10 GB of memory.

这篇关于如何确定Redis内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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