redis4.0 release https://github.com/antirez/redis/blob/4.0/00-RELEASENOTES
Redis uses now less memory in order to store the same amount of data.
也就是说相对于之前的版本,redis使用更少的内存去存储相同的数据。
基于以下以下两点。
1.SDS improvements for speed and maximum string length.This makes Redis more memory efficient in different use cases.
- The gain depends a lot on the kind of dataset stored.(不能特别清晰的理解)
1的意思其实是在redis3.2以前,当value的大于39字节那么将会使用更耗费内存的方式。而redis3.2之后,大于44字节才会使用更耗费的内存方式。那么在39-44之间大小value将会减少内存使用。
https://mp.weixin.qq.com/s/fDneukqWu8mbXuybJ7JFgw
中给出了测试:
写入10亿个44字节的key和value
Redis 3.0.7的内存消耗:
used_memory_human:177G
Redis 4.0.12的内存消耗:
used_memory_human:147G
虽然内存得到了极大的节省,但是对使用者来说其实是有限的优化(39<字节数<=44)。
对于2,作者在文章和release中都没有提及。只有一句话:The gain depends a lot on the kind of dataset stored.(原理后续清晰了再更新)。
测试先行,做以下两个测试。
为了避免jemalloc的影响,测试时,使用新版jemalloc。
实验一:测试set(字节数<39)value
./redis-benchmark -h 127.0.0.1 -p 6379 -t set -r 1000000000 -d 20 -c 50 -n 200000000
其中value为20个字节:
127.0.0.1:6379> keys *
1) "key:000618668452"
2) "key:000667355381"
127.0.0.1:6379> get key:000618668452
“xxxxxxxxxxxxxxxxxxxx” (20个字节)
测试结果:
redis-2.8 jemalloc 5.0
# Memory
used_memory:20954659568
used_memory_human:19.52G
used_memory_rss:21504397312
used_memory_peak:20957143768
used_memory_peak_human:19.52G
used_memory_lua:36864
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-5.1.0
# Keyspace
db0:keys=180830362,expires=0,avg_ttl=0
redis-4.0 jemalooc 4.0
# Memory
used_memory:18061462536
used_memory_human:16.82G
used_memory_rss:18540425216
used_memory_rss_human:17.27G
used_memory_peak:18064265384
used_memory_peak_human:16.82G
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-4.0.3
# Keyspace
db0:keys=180831028,expires=0,avg_ttl=0
实验结果表面:当value字节数为20时,4.0比2.8节省2.7g。节省内存13.83%
实验二:测试set(字节数>44)value
./redis-benchmark -h 127.0.0.1 -p 6379 -t set -r 1000000000 -d 128 -c 50 -n 200000000
其中value为128个字节。
测试结果:
redis-2.8 jemalloc 5.0
# Memory
used_memory:44099888200
used_memory_human:41.07G
used_memory_rss:44692525056
used_memory_peak:44102623176
used_memory_peak_human:41.07G
used_memory_lua:36864
mem_fragmentation_ratio:1.01
mem_allocator:jemalloc-5.1.0
redis-4.0 jemalooc 4.0
# Memory
used_memory:42654566320
used_memory_human:39.73G
used_memory_rss:43728355328
used_memory_rss_human:40.73G
used_memory_peak:42656988064
used_memory_peak_human:39.73G
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.03
mem_allocator:jemalloc-4.0.3
实验结果表面:当value字节数为128时,4.0比2.8节省1.34g。节省内存:3.26%
结论:目前因为原理不是特别清楚,不能明晰的描述4.0如何节省内存。但在测试hset,set不同数量大小的情况下,redis4.0使用的内存普遍都比2.8小。
网友评论