메모리 사용량과 단편화 분석, active defrag 활성화
Redis메모리명령어
INFO memory
# Fields to check: used_memory_human, used_memory_rss_human, mem_fragmentation_ratio, mem_fragmentation_bytes, allocator_frag_ratio
MEMORY STATS
# If fragmentation is high and persistent, enable active defrag (requires jemalloc):
CONFIG SET activedefrag yes
CONFIG SET active-defrag-ignore-bytes 100mb
CONFIG SET active-defrag-threshold-lower 10
# Ask the allocator to return free pages to the OS:
MEMORY PURGE하는 일
Redis가 데이터에 할당한 메모리(used_memory)와 OS가 보는 RSS의 차이, 단편화 비율, 메모리 내역을 보여 준다. 필요하면 런타임에 active defrag를 활성화한다.
사용 시점
RSS가 데이터셋보다 확연히 클 때, 대량 삭제/만료 후 메모리가 줄지 않을 때, 또는 OOM 위험이 나타날 때.
주의
mem_fragmentation_ratio는 작은 데이터셋에서 오해를 일으킨다(예: 2 MB 데이터에서 4.0). 절대값은 mem_fragmentation_bytes를 본다. 비율이 1 미만이면 단편화가 아니라 스와핑을 의미하며 지연을 일으킨다. active defrag는 CPU를 소비하므로 active-defrag-cycle-max로 제한한다. 영구화하려면 CONFIG REWRITE 또는 redis.conf가 필요하다.