我正在尝试优化列表的内存使用量。在阅读了这个great memory optimization article之后,我强迫使用ziplists来看看它会产生什么效果,但即使我的RDB减少了70%,Redis消耗的内存也没有减少......
以下是有关我的实例的一些数据:
# Memory
used_memory:28894160544
used_memory_human:26.91G
used_memory_rss:29423480832
used_memory_peak:28894160544
used_memory_peak_human:26.91G
used_memory_lua:33792
mem_fragmentation_ratio:1.02
mem_allocator:jemalloc-3.6.0
# Keyspace
db0:keys=8433742,expires=0,avg_ttl=0
然后我应用了这些设置:
list-max-ziplist-entries 1000
list-max-ziplist-value 10000
(我知道那些很高并且可能很危险......我只想保证涵盖每个清单......大多数清单都有75个项目(我将强制它们保持这个尺寸)少于1000个每个项目的字节数)
导致:
# Memory
used_memory:26486158232
used_memory_human:24.67G
used_memory_rss:26687750144
used_memory_peak:26553209288
used_memory_peak_human:24.73G
used_memory_lua:33792
mem_fragmentation_ratio:1.01
mem_allocator:jemalloc-3.6.0
此外,我在前后调试了几个列表,看看发生了什么......这里有一些例子:
列出A(75项):
- Before:
Value at:0x7f0ab6b04940 refcount:1 encoding:linkedlist serializedlength:29332 lru:0 lru_seconds_idle:2623116
- After:
Value at:0x7f9b8a464920 refcount:1 encoding:ziplist serializedlength:8151 lru:0 lru_seconds_idle:2623697
列表B(56项):
- Before:
Value at:0x7f0e62d83270 refcount:1 encoding:linkedlist serializedlength:28797 lru:0 lru_seconds_idle:2623201
- After:
Value at:0x7f9ee1b9dfa0 refcount:1 encoding:ziplist serializedlength:4438 lru:0 lru_seconds_idle:2623692
LIST C(15项):
- Before:
Value at:0x7f0c8fbdcfb0 refcount:1 encoding:linkedlist serializedlength:1160 lru:0 lru_seconds_idle:2623249
- After:
Value at:0x7f9d3852d330 refcount:1 encoding:ziplist serializedlength:720 lru:0 lru_seconds_idle:2623675
这分别让我 72%, 85%和 38%对象减少
除了我想要的东西之外,所有东西都减少了很少的内存,这是Redis消耗的总内存:(
所以我主要有3个问题: