debugModerate
Redis takes up all the Memory and Crashes
Viewed 0 times
redistheallcrashesmemoryandtakes
Problem
A redis server v2.8.4 is running on a Ubuntu 14.04 VPS with 8 GB RAM and 16 GB swap space (on SSDs). However
From
Restarting
Question: Why does
Is it true that setting
After restarting redis-server
Redis version:
Update
When
```
127.0.0.1:6379> INFO all
# Server
redis_version:2.8.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a44a05d76f06a5d9
redis_mode:standalone
os:Linux 3.13.0-24-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.2
process_id:26858
run_id:4d4a507b325e567d5ada203a0c65891bcf4d02de
tcp_port:6379
uptime_in_seconds:100011
uptime_in_days:1
hz:10
lru_clock:165668
config_file:/etc/redis/redis.conf
# Clients
connected_clients:60
client_longest_output_list:768774
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:23973468008
used_memory
htop shows that redis alone is taking up 22.4 G of memory!redis-server eventually crashed due to out of memeory. Mem and Swp both hits 100% then redis-server is killed along with other services. From
dmesg:[165578.047682] Out of memory: Kill process 10155 (redis-server) score 834 or sacrifice child
[165578.047896] Killed process 10155 (redis-server) total-vm:31038376kB, anon-rss:5636092kB, file-rss:0kBRestarting
redis-server from etiher a OOM crash or a service redis-server force-reload causes memory usage to drop to <100MB. Question: Why does
redis-server occupy more and more memory till it crashes? How can we prevent this?Is it true that setting
maxmemory will not work because once redis hits the maxmemory limit, it will start removing data?After restarting redis-server
Redis version:
Redis server v=2.8.4 sha=00000000:0 malloc=jemalloc-3.4.1 bits=64 build=a44a05d76f06a5d9Update
When
htop reports the memory usage of redis-server to be 4.4G RAM and 22.6G Swap, the amount of space taken up by all the keys in redis is only 60.59636307 MB, as reported by rdbtools. This is also the amount of RAM taken up by redis-server right after it restarts.INFO ALL when redis-server is taking up tons of memorymem_fragmentation_ratio:0.19```
127.0.0.1:6379> INFO all
# Server
redis_version:2.8.4
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a44a05d76f06a5d9
redis_mode:standalone
os:Linux 3.13.0-24-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.2
process_id:26858
run_id:4d4a507b325e567d5ada203a0c65891bcf4d02de
tcp_port:6379
uptime_in_seconds:100011
uptime_in_days:1
hz:10
lru_clock:165668
config_file:/etc/redis/redis.conf
# Clients
connected_clients:60
client_longest_output_list:768774
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:23973468008
used_memory
Solution
- Use the
maxmemoryto set a limit to how much your Redis database can grow too. Failing to do so, Redis will grow until the OS will kill it once memory is exhausted (per your current experience).
- The usage of
maxmemoryshould be coupled withmaxmemory-policy- you can choose from different eviction policies depending on your use case's requirements. For example, if you use theallkeys-lrueviction policy, Redis will indeed start evicting (the least recently used) data oncemaxmemoryhas been reached. Alternatively, you can instruct Redis to evict only expire-able data with thevolatile-lruorvolatile-randompolicies. Lastly, you can set the policy tonoevictionbut that would mean that once memory has been exhausted, Redis will deny further writes with an OOM message.
Edit:
First disable swap - Redis and swap don't mix easily and this can certainly cause slowness.
Also do
free -m instead of top for the full picture of your RAM's state (http://www.linuxatemyram.com/).Context
StackExchange Database Administrators Q#72661, answer score: 11
Revisions (0)
No revisions yet.