Redis OOM error with eviction

329 views
Skip to first unread message

Owais Ahmad

unread,
Jul 29, 2016, 3:53:35 AM7/29/16
to Redis DB
Hello,

I am using redis 3.2.1 on a 64-bit machine with 4GB RAM and 2 cores.

Here is my config and stats:
maxmemory=2.5gb.
used-memory=2.4gb.
db size=volatile-keys=24,486,077.
expired-keys=1,870,148.
evicted-keys=2945
operations per second=800
background-saving=on

Application intermittently gives OOM error even when I have enabled volatile-ttl eviction policy.
Logs do not suggest anything which I can use to isolate the problem.

When I restart redis server, the used memory drops low and things operate fine for a few days. This leads me to think that redis is not freeing up memory upon key expiry. 

There is no way that the application can store these many keys, as when redis starts, the key volume is low, and it increases very slowly.
How much overhead per KV pair does redis store?

Is there a way to say x bytes of key value pairs will require y bytes of RAM on redis, so that I can increase the memory limit if the requirement is high?


Regards,
Owais

andyh

unread,
Jul 29, 2016, 10:06:27 PM7/29/16
to redi...@googlegroups.com
Votatile-ttl only evict keys with expiration set. Probably you should look at allkeys-lru?

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--
andyh
Andy Huang (Huangkejun)

Owais Ahmad

unread,
Jul 30, 2016, 10:32:49 AM7/30/16
to redi...@googlegroups.com
On Sat, Jul 30, 2016 at 7:06 AM, andyh <ma...@andyh.io> wrote:
Votatile-ttl only evict keys with expiration set. Probably you should look at allkeys-lru?

On Fri, Jul 29, 2016 at 4:53 PM, Owais Ahmad <millenn...@gmail.com> wrote:
Hello,

I am using redis 3.2.1 on a 64-bit machine with 4GB RAM and 2 cores.

Here is my config and stats:
maxmemory=2.5gb.
used-memory=2.4gb.
db size=volatile-keys=24,486,077.
​Yes but as I showed in the above statement, 100% of the keys in my db are volatile, so it makes no difference to use allkeys-xxx or volatile-xxx​
 
expired-keys=1,870,148.
evicted-keys=2945
operations per second=800
background-saving=on

Application intermittently gives OOM error even when I have enabled volatile-ttl eviction policy.
Logs do not suggest anything which I can use to isolate the problem.

When I restart redis server, the used memory drops low and things operate fine for a few days. This leads me to think that redis is not freeing up memory upon key expiry. 

There is no way that the application can store these many keys, as when redis starts, the key volume is low, and it increases very slowly.
How much overhead per KV pair does redis store?

Is there a way to say x bytes of key value pairs will require y bytes of RAM on redis, so that I can increase the memory limit if the requirement is high?


Regards,
Owais

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--
andyh
Andy Huang (Huangkejun)

--
You received this message because you are subscribed to a topic in the Google Groups "Redis DB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/redis-db/ArAuk9IH7NQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to redis-db+u...@googlegroups.com.

andyh

unread,
Jul 30, 2016, 10:01:46 PM7/30/16
to redi...@googlegroups.com
Oh I see you have background-saving turned on. Do you have many write operations? If you do, you need to configure your machine to have twice as much as your Redis memory. 

"If you are using Redis in a very write-heavy application, while saving an RDB file on disk or rewriting the AOF logRedis may use up to 2 times the memory normally used. The additional memory used is proportional to the number of memory pages modified by writes during the saving process, so it is often proportional to the number of keys (or aggregate types items) touched during this time. Make sure to size your memory accordingly."

More can be found at: http://redis.io/topics/admin



Owais Ahmad

unread,
Jul 31, 2016, 2:00:50 PM7/31/16
to Redis DB
Yes, you're right I need to have 2x the memory but I actually need to theoretically calculate how much RAM would I need to be able to save x keys in redis. I need to quantify the overhead per key. Because I can't believe that the application actually saves that many bytes of key value pairs at one time...!

Owais Ahmad

unread,
Aug 1, 2016, 6:12:59 AM8/1/16
to redi...@googlegroups.com
Also, the applicaiton operates under same load every day, but the cache use memory keeps on increasing very slowly per day, until after some weeks, it reaches the max memory limit. All keys are volatile with ttl < 3600 seconds, there is a valid eviction policy, but I wonder why redis memory volume doesn't stay stable, and keeps increasing till I give it a restart...

Michel Comeau

unread,
Aug 10, 2016, 10:57:08 AM8/10/16
to Redis DB
If i remember well, I had to configure the app or the system not to use cache memory but to evict.

Been a long time, so i'm not so sure how to do it anymore.

Maybe that will trigger someone's memory ?

Also, eviction rule is not something that will trigger all the time from the system:

I believe eviction works this way:

1) If you try to access an expired key that was not evicted yet, it will be evicted at that point and return it does not exist.
2) If you fill the memory, system will pick 1 or a few (semi?) random entries, and evict the oldest, you can read this in redis site.
3) if you don't like to have all memory used, you can limit redis to a smaller memory usage

Regards,
Michel 
Reply all
Reply to author
Forward
0 new messages