一、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

本文详细介绍了在Redis集群部署中遇到的内存分配不均问题,通过查看内存使用、分析主从关系及哈希槽分配进行问题排查。尝试了Predixy代理、缩减节点数等解决方案,最终通过调整节点内存分配解决了问题。
最低0.47元/天 解锁文章
2250

被折叠的 条评论
为什么被折叠?



