Redis Memory Usage Explanation
Redis real-used memory =
process self memory
+object memory
+buffer memory
+fragmentation memory
object memory
sizeof(keys) + sizeof(values)
buffer memory
buffer memory includes client buffer
, repl buffer
and AOF buffer
client buffer
//普通客户端
client-output-buffer-limit normal 0 0 0
//从客户端 (如果60秒内缓冲区消耗持续大于64MB或者直接超过256MB时)
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit slave 4096mb 4096mb 1800
//订阅客户端
client-output-buffer-limit pubsub 32mb 8mb 60
repl buffer
复制积压缓冲区,由repl-backlog-size
参数控制,默认1MB
# redis-cli info |grep repl
repl_backlog_active:1 // 开启复制缓冲区
repl_backlog_size:1048576 // 缓冲区最大长度
repl_backlog_first_byte_offset:7479 // 起始偏移量,计算当前缓冲区可用范围
repl_backlog_histlen:1048576 // 已保存数据的有效长度
AOF buffer
will buffer writting commands during aofwrite, controlled by Redis
fragmentation memory
controlled by redis process, append
, setrange
, expire
and del
etc. commands will increase the mem_fragmentation_ratio
# redis-cli info |grep frag
allocator_frag_ratio:1.20
allocator_frag_bytes:290200
mem_fragmentation_ratio:18.78
mem_fragmentation_bytes:14394880
active_defrag_running:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here