Skip to content

Redis Memory Usage Explanation

homepage-banner

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

// Regular client
client-output-buffer-limit normal 0 0 0
// Replica client (if buffer consumption exceeds 64MB continuously within 60 seconds or directly exceeds 256MB)
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit slave 4096mb 4096mb 1800
// Subscription client
client-output-buffer-limit pubsub 32mb 8mb 60

repl buffer

Copy the backlog buffer controlled by the repl-backlog-size parameter, defaulting to 1MB

# redis-cli info |grep repl
repl_backlog_active:1                   // Enable replication backlog
repl_backlog_size:1048576               // Maximum size of backlog
repl_backlog_first_byte_offset:7479     // Starting offset, calculating the available range of current backlog
repl_backlog_histlen:1048576            // Effective length of saved data

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
Leave a message