【问题标题】:Redis taking too much memoryRedis 占用太多内存
【发布时间】:2019-01-10 16:46:25
【问题描述】:

我在两个 centos 6 虚拟机中设置了一个 Redis(版本 4.0.6)哨兵集群。主从 Redis 服务器的 maxmemory 设置为 10GB,maxmemory_policy 为 volatile-lru。

问题是,两台服务器都占用了大量内存。

大师

used_memory:8959732536
used_memory_human:8.34G
used_memory_rss:14763728896
used_memory_rss_human:13.75G
used_memory_peak:10002148536
used_memory_peak_human:9.32G
used_memory_peak_perc:89.58%
used_memory_overhead:1344839894
used_memory_startup:761776
used_memory_dataset:7614892642
used_memory_dataset_perc:85.00%
total_system_memory:20957556736
total_system_memory_human:19.52G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:10000000000
maxmemory_human:9.31G
maxmemory_policy:volatile-lru
mem_fragmentation_ratio:1.65
mem_allocator:jemalloc-3.6.0
active_defrag_running:0
lazyfree_pending_objects:0

从属

used_memory:8927665872
used_memory_human:8.31G
used_memory_rss:16422535168
used_memory_rss_human:15.29G
used_memory_peak:10000009472
used_memory_peak_human:9.31G
used_memory_peak_perc:89.28%
used_memory_overhead:1340505548
used_memory_startup:761792
used_memory_dataset:7587160324
used_memory_dataset_perc:84.99%
total_system_memory:20957556736
total_system_memory_human:19.52G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:10000000000
maxmemory_human:9.31G
maxmemory_policy:volatile-lru
mem_fragmentation_ratio:1.84
mem_allocator:jemalloc-3.6.0
active_defrag_running:0
lazyfree_pending_objects:0

Redis 在主服务器和从服务器上分别占用 14064.8 MB 和 15664.2 MB。 我确实有很多数据存储在redis中。他们中的大多数都设置了到期日,有些没有到期日。

问题是即使将最大内存设置为 10 GB,为什么 redis 在 VM 中占用大约 15 GB。

我看到已用内存低于 10GB,而 rss 内存为 15GB。

我确实运行了 MEMORY PURGE,它清除了一些 rss 内存,但它会在几分钟内重新填充并继续增长。

关于如何控制内存消耗的任何建议或此问题的永久解决方案。我应该增加 VM 中的 RAM 吗?如果是,我应该添加多少 RAM 来处理这种情况。

【问题讨论】:

    标签: redis predis


    【解决方案1】:

    RSS 内存将始终大于 Redis 用于数据集的实际内存。在您的情况下,您似乎还遭受内存碎片的困扰,因此您应该考虑启用主动碎片整理程序。

    也就是说,为您的服务器分配更多 RAM 将使它们达到更高的碎片率,因此您添加的内存越多,达到内存压力所需的时间就越长。由于碎片化取决于使用情况,很难准确地说出您还需要多少,但在大多数情况下,碎片化会在一段时间后达到稳定状态,因此应该可以为您提供一些指示。

    【讨论】:

      猜你喜欢
      • 2015-10-14
      • 2013-07-18
      • 2013-07-11
      • 2020-05-18
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 2011-09-20
      • 2012-05-23
      相关资源
      最近更新 更多