Redis常用数据结构内存占用分析

结论:
一个列表存100万个不同手机号码,占用内存约10MB
一个集合存100万个不同手机号码,占用内存约55MB
一个有序集合存100万个不同手机号码,占用内存约100MB
一个哈希表存100万个不同手机号码作为键,随机0到当前时间戳为值,占用内存约70MB
100万个不同手机号码到字符串mobile_string_*(键为mobile_string_手机号码,值取0到当前时间戳之间的随机值):约110MB
当前时间戳:1524194686

分析步骤:

第一次存入100万个手机号码基数为1370000000、每次递增1值10之间的随机值
第二次存入100万个手机号基数1880000000,每次递增1值10之间的随机值
初始内存占用:
used_memory:1031392
used_memory_human:1007.22K
used_memory_rss:2412544
used_memory_rss_human:2.30M
used_memory_peak:1031392
used_memory_peak_human:1007.22K
used_memory_peak_perc:100.00%
used_memory_overhead:1030366
used_memory_startup:980736
used_memory_dataset:1026
used_memory_dataset_perc:2.03%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:2.34
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

存入100万个不同手机号码到列表mobile_list后:
used_memory:11096688
used_memory_human:10.58M
used_memory_rss:12513280
used_memory_rss_human:11.93M
used_memory_peak:11096688
used_memory_peak_human:10.58M
used_memory_peak_perc:100.30%
used_memory_overhead:1030438
used_memory_startup:980736
used_memory_dataset:10066250
used_memory_dataset_perc:99.51%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.13
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

再存入100万个不同手机号码到列表mobile_list后:
used_memory:21162864
used_memory_human:20.18M
used_memory_rss:22646784
used_memory_rss_human:21.60M
used_memory_peak:21162864
used_memory_peak_human:20.18M
used_memory_peak_perc:100.16%
used_memory_overhead:1030438
used_memory_startup:980736
used_memory_dataset:20132426
used_memory_dataset_perc:99.75%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.07
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

接着存入100万个不同手机号码到集合mobile_set后:
used_memory:77551632
used_memory_human:73.96M
used_memory_rss:87523328
used_memory_rss_human:83.47M
used_memory_peak:77551632
used_memory_peak_human:73.96M
used_memory_peak_perc:100.04%
used_memory_overhead:1030478
used_memory_startup:980736
used_memory_dataset:76521154
used_memory_dataset_perc:99.94%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.13
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

再存入100万个不同手机号码到集合mobile_set
used_memory:133940240
used_memory_human:127.74M
used_memory_rss:153055232
used_memory_rss_human:145.96M
used_memory_peak:133940240
used_memory_peak_human:127.74M
used_memory_peak_perc:100.02%
used_memory_overhead:1030478
used_memory_startup:980736
used_memory_dataset:132909762
used_memory_dataset_perc:99.96%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.14
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

接着存入100万个不同手机号码到有序集合mobile_sorted(排序分数取0到当前时间戳之间的随机值)
used_memory:243671328
used_memory_human:232.38M
used_memory_rss:256581632
used_memory_rss_human:244.70M
used_memory_peak:243671328
used_memory_peak_human:232.38M
used_memory_peak_perc:100.01%
used_memory_overhead:1030518
used_memory_startup:980736
used_memory_dataset:242640810
used_memory_dataset_perc:99.98%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.05
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

再存入100万个不同手机号码到有序集合mobile_sorted(排序分数取0到当前时间戳之间的随机值):
used_memory:353394768
used_memory_human:337.02M
used_memory_rss:376295424
used_memory_rss_human:358.86M
used_memory_peak:353394768
used_memory_peak_human:337.02M
used_memory_peak_perc:100.01%
used_memory_overhead:1030518
used_memory_startup:980736
used_memory_dataset:352364250
used_memory_dataset_perc:99.99%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.06
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

存入100万个不同手机号码到哈希表mobile_hash(键为手机号码,值取0到当前时间戳之间的随机值):
used_memory:425783536
used_memory_human:406.06M
used_memory_rss:440791040
used_memory_rss_human:420.37M
used_memory_peak:425783536
used_memory_peak_human:406.06M
used_memory_peak_perc:100.01%
used_memory_overhead:1030558
used_memory_startup:980736
used_memory_dataset:424752978
used_memory_dataset_perc:99.99%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.04
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

再存入100万个不同手机号码到哈希表mobile_hash(键为手机号码,值取0到当前时间戳之间的随机值):
used_memory:498172144
used_memory_human:475.09M
used_memory_rss:522575872
used_memory_rss_human:498.37M
used_memory_peak:498172144
used_memory_peak_human:475.09M
used_memory_peak_perc:100.01%
used_memory_overhead:1030558
used_memory_startup:980736
used_memory_dataset:497141586
used_memory_dataset_perc:99.99%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.05
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

存入100万个不同手机号码到字符串mobile_string_*(键为mobile_string_手机号码,值取0到当前时间戳之间的随机值):
used_memory:610949104
used_memory_human:582.65M
used_memory_rss:636940288
used_memory_rss_human:607.43M
used_memory_peak:610949104
used_memory_peak_human:582.65M
used_memory_peak_perc:100.01%
used_memory_overhead:57807742
used_memory_startup:980736
used_memory_dataset:553141362
used_memory_dataset_perc:90.68%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.04
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

再存入100万个不同手机号码到字符串mobile_string_*(键为mobile_string_手机号码,值取0到当前时间戳之间的随机值):
used_memory:706948944
used_memory_human:674.20M
used_memory_rss:734519296
used_memory_rss_human:700.49M
used_memory_peak:706948944
used_memory_peak_human:674.20M
used_memory_peak_perc:100.00%
used_memory_overhead:97807742
used_memory_startup:980736
used_memory_dataset:609141202
used_memory_dataset_perc:86.28%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.04
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

flushdb
OK
(5.45s)

used_memory:1030592
used_memory_human:1006.44K
used_memory_rss:119296000
used_memory_rss_human:113.77M
used_memory_peak:706948944
used_memory_peak_human:674.20M
used_memory_peak_perc:0.15%
used_memory_overhead:1030366
used_memory_startup:980736
used_memory_dataset:226
used_memory_dataset_perc:0.45%
total_system_memory:8589934592
total_system_memory_human:8.00G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:115.74
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

发表评论

电子邮件地址不会被公开。 必填项已用*标注