优化 Redis 集群缓存分配:解决节点间分配不均导致内存溢出问题

一、Redis 集群部署简介

在现代应用程序中,缓存被广泛应用以提高性能和减轻后端数据库的压力。本文将探讨面对 Redis 集群缓存分配不均问题时的解决方法。

我们的 Redis 集群部署包括 3 主 3 从,每个节点分配内存 4G(服务器总内存32G),内存淘汰策略相同:volatile-lru

二、问题描述

在性能测试过程中,通过 pinpoint 监控发现报错:OOM

Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: OOM command not allowed when used memory> 'maxmemory'

三、排查、分析问题过程

1. 查看内存使用情况

清空缓存后,再次执行性能测试一段时间,使用 info memory 查看各节点内存使用情况,发现 2、6 节点内存快速上升,其它节点内存使用率很低。

例如,2 节点内存达到 3.81G,6 节点内存达到 3.8G,而其他 4 个节点内存仅为 80M 左右。

[root@iZ2ze3e0bvnd1hf5xbkxn3Z redis01]# ./redis-cli -h 192.168.0.213 -p 6692 -c -a Tiye@54L2!
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.0.213:6692> info memory
# Memory
used_memory:4095914816
used_memory_human:3.81G
used_memory_rss:4473937920
used_memory_rss_human:4.17G
used_memory_peak:4105896552
used_memory_peak_human:3.82G
used_memory_peak_perc:99.76%
used_memory_overhead:5159996
used_memory_startup:1483832
used_memory_dataset:4090754820
used_memory_dataset_perc:99.91%
allocator_allocated:4095978056
allocator_active:4728315904
allocator_resident:4765335552
total_system_memory:33019609088
total_system_memory_human:30.75G
used_memory_lua:30720
used_memory_lua_human:30.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:4096000000
maxmemory_human:3.81G
maxmemory_policy:volatile-lru
allocator_frag_ratio:1.15
allocator_frag_bytes:632337848
allocator_rss_ratio:1.01
allocator_rss_bytes:37019648
rss_overhead_ratio:0.94
rss_overhead_bytes:-291397632
mem_fragmentation_ratio:1.09
mem_fragmentation_bytes:
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值