Bird
Raised Fist0
Redisquery~10 mins

Memory usage analysis (INFO memory) in Redis - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Memory usage analysis (INFO memory)
Run INFO memory command
↓
Receive memory stats
↓
Parse key metrics
↓
Analyze memory usage
↓
Identify bottlenecks or inefficiencies
↓
Optimize or monitor accordingly
The flow shows running the INFO memory command, getting memory stats, parsing key metrics, analyzing usage, and then optimizing or monitoring.
Execution Sample
Redis
127.0.0.1:6379> INFO memory
# Memory
used_memory:1024000
used_memory_rss:2048000
used_memory_peak:3072000
mem_fragmentation_ratio:2.0
mem_allocator:jemalloc-5.1.0
This command shows Redis memory usage details like used memory, peak memory, and fragmentation ratio.
Execution Table
StepActionMetric ExtractedValueMeaning
1Run INFO memory commandused_memory1024000Bytes of memory Redis is using
2Parse outputused_memory_rss2048000Memory allocated by OS (resident set size)
3Parse outputused_memory_peak3072000Highest memory used since start
4Parse outputmem_fragmentation_ratio2.0Memory overhead due to fragmentation
5Parse outputmem_allocatorjemalloc-5.1.0Memory allocator used by Redis
6Analyze fragmentationmem_fragmentation_ratio2.0High fragmentation means inefficient memory use
7DecisionOptimize or monitor-If fragmentation >1.5, consider optimization
8Exit--Analysis complete
💡 All key memory metrics extracted and analyzed for optimization decisions
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
used_memory010240001024000102400010240001024000
used_memory_rss002048000204800020480002048000
used_memory_peak000307200030720003072000
mem_fragmentation_ratio00002.02.0
mem_allocatorunknownunknownunknownunknownjemalloc-5.1.0jemalloc-5.1.0
Key Moments - 3 Insights
Why is used_memory_rss larger than used_memory?
used_memory_rss includes all memory allocated by the OS, including fragmentation and overhead, while used_memory is the actual memory Redis is using for data. See execution_table rows 1 and 2.
What does a mem_fragmentation_ratio of 2.0 mean?
It means Redis is using twice as much memory as the data size due to fragmentation or allocator overhead. High fragmentation can cause inefficiency. See execution_table row 4 and 6.
Why do we check used_memory_peak?
used_memory_peak shows the highest memory Redis has used since start, helping to understand memory spikes. See execution_table row 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what is the mem_fragmentation_ratio value?
A1.0
B2.0
C0.5
D3.0
💡 Hint
Check the 'Metric Extracted' and 'Value' columns at step 4 in execution_table.
At which step do we identify that memory fragmentation might be a problem?
AStep 6
BStep 5
CStep 2
DStep 7
💡 Hint
Look for the step where mem_fragmentation_ratio is analyzed in execution_table.
If used_memory_peak was lower than used_memory, what would that indicate?
AMemory usage is currently at its highest
BMemory fragmentation is low
CMemory usage has never been that high before
DRedis is using a different allocator
💡 Hint
Compare used_memory and used_memory_peak values in variable_tracker.
Concept Snapshot
Run the Redis command INFO memory to get memory stats.
Key metrics: used_memory, used_memory_rss, used_memory_peak, mem_fragmentation_ratio.
used_memory = actual data memory used.
used_memory_rss = OS memory allocated (includes fragmentation).
mem_fragmentation_ratio >1 means memory overhead.
Use these to monitor and optimize Redis memory usage.
Full Transcript
This visual execution shows how to analyze Redis memory usage using the INFO memory command. First, the command is run to get memory statistics. Then key metrics like used_memory, used_memory_rss, used_memory_peak, and mem_fragmentation_ratio are extracted. The used_memory shows actual memory used by Redis data. The used_memory_rss shows memory allocated by the operating system, which is usually larger due to fragmentation and overhead. The used_memory_peak shows the highest memory used since Redis started, helping identify memory spikes. The mem_fragmentation_ratio indicates how much extra memory is used due to fragmentation; a value of 2.0 means twice the memory is used compared to actual data size, which is inefficient. By analyzing these values, one can decide if optimization or monitoring is needed. This step-by-step trace helps beginners understand how Redis memory metrics relate and how to interpret them for better memory management.

Practice

(1/5)
1. What does the used_memory field in the INFO memory command represent in Redis?
easy
A. The total number of keys stored in Redis
B. The amount of memory Redis is currently using in bytes
C. The peak memory usage recorded since Redis started
D. The fragmentation ratio of Redis memory

Solution

  1. Step 1: Understand the INFO memory output

    The INFO memory command shows various memory stats about Redis.
  2. Step 2: Identify used_memory meaning

    used_memory specifically shows how many bytes Redis is currently using in RAM.
  3. Final Answer:

    The amount of memory Redis is currently using in bytes -> Option B
  4. Quick Check:

    used_memory = current memory used [OK]
Hint: Remember: 'used_memory' means current bytes used [OK]
Common Mistakes:
  • Confusing 'used_memory' with total keys count
  • Mixing 'used_memory' with peak memory
  • Thinking it shows fragmentation ratio
2. Which of the following is the correct Redis CLI command to check memory usage details?
easy
A. GET MEMORY INFO
B. MEMORY USAGE
C. SHOW MEMORY
D. INFO memory

Solution

  1. Step 1: Recall Redis commands for memory info

    The Redis command to get detailed memory info is INFO memory.
  2. Step 2: Check other options

    MEMORY USAGE exists but returns usage for a single key, not overall memory info. The others are invalid commands.
  3. Final Answer:

    INFO memory -> Option D
  4. Quick Check:

    Use INFO memory to get memory stats [OK]
Hint: Use 'INFO memory' to get full memory stats [OK]
Common Mistakes:
  • Using MEMORY USAGE to get overall memory info
  • Typing invalid commands like SHOW MEMORY
  • Confusing command names
3. Given this Redis INFO memory output snippet:
used_memory:1048576
used_memory_peak:2097152
mem_fragmentation_ratio:1.5

What does the mem_fragmentation_ratio value of 1.5 indicate?
medium
A. Redis memory is fragmented, using 1.5 times more memory than needed
B. Redis is using 50% more memory than allocated
C. Redis has 1.5 million keys stored
D. Redis memory usage is optimal

Solution

  1. Step 1: Understand mem_fragmentation_ratio

    This ratio shows how much extra memory Redis uses due to fragmentation.
  2. Step 2: Interpret value 1.5

    A value of 1.5 means Redis uses 1.5 times the memory it actually needs, indicating fragmentation.
  3. Final Answer:

    Redis memory is fragmented, using 1.5 times more memory than needed -> Option A
  4. Quick Check:

    Fragmentation ratio > 1 means extra memory used [OK]
Hint: Fragmentation ratio >1 means extra memory used [OK]
Common Mistakes:
  • Thinking ratio shows number of keys
  • Assuming ratio below 1 means fragmentation
  • Confusing fragmentation with peak memory
4. You run INFO memory and see used_memory_peak is lower than expected despite high used_memory. What is the likely cause?
medium
A. The command syntax is incorrect
B. Redis is leaking memory and reporting wrong values
C. Redis memory peak resets after restart, but current usage is higher
D. Redis has no keys stored

Solution

  1. Step 1: Understand used_memory_peak

    This shows the highest memory Redis used since last restart.
  2. Step 2: Compare with used_memory

    If current used_memory is higher, it means memory usage increased after peak was reset (likely after restart).
  3. Final Answer:

    Redis memory peak resets after restart, but current usage is higher -> Option C
  4. Quick Check:

    Peak resets on restart, current usage can be higher [OK]
Hint: Peak resets on restart; current can exceed peak after restart [OK]
Common Mistakes:
  • Assuming memory leak without evidence
  • Thinking command syntax is wrong
  • Believing no keys means memory usage
5. You notice your Redis server's mem_fragmentation_ratio is consistently above 2.0. What is the best action to reduce memory fragmentation?
hard
A. Run MEMORY PURGE command to defragment memory
B. Increase the number of keys stored
C. Restart Redis to reset memory fragmentation
D. Delete all keys to free memory

Solution

  1. Step 1: Understand high fragmentation impact

    A ratio above 2 means Redis uses twice the memory needed, hurting performance.
  2. Step 2: Identify Redis command to reduce fragmentation

    MEMORY PURGE triggers allocator to release unused memory and reduce fragmentation.
  3. Step 3: Evaluate other options

    Restarting helps temporarily but is disruptive. Increasing keys worsens memory. Deleting all keys is drastic and unnecessary.
  4. Final Answer:

    Run MEMORY PURGE command to defragment memory -> Option A
  5. Quick Check:

    Use MEMORY PURGE to reduce fragmentation [OK]
Hint: Use MEMORY PURGE to reduce fragmentation without restart [OK]
Common Mistakes:
  • Restarting Redis as first fix
  • Adding more keys to fix memory
  • Deleting all keys unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard