Very simple: when a malloc() fails, an OOME (runtime exception) is
thrown. We can catch it and see if we can help reducing memory by
evicting elements from the cache. Note that OOMEs are also thrown when
the stack is exhausted (IIRC) and when a new thread cannot be created.
Definitely something worth trying out...
On 1/14/11 3:26 PM, david marion wrote:
We could definitely try that. I'm not sure what happens internally when an OOM is
raised by the VM.
> Date: Fri, 14 Jan 2011 09:40:37 +0100
> From: bban(a)redhat.com
> To: infinispan-dev(a)lists.jboss.org
> Subject: Re: [infinispan-dev] ISPN-863 - Thoughts / Questions
>
> Excellent, memory based eviction is very important ! This has been on
> the todo list for years !
>
> One thing you might want to think about is - *in addition* to what you
> say below - whether you want to add an OOME handler, which evits on OOME
> caused by putXXX() methods.
>
> For example, you could wrap all methods which add to the map to catch
> OOMEs. When this is the case, kick off the eviction handler to evict
> elements immediately. Kind of like a second line of defense against OOMEs...
>
>
> WDYT ?
>
>
>
> On 1/14/11 4:22 AM, david marion wrote:
>>
>> I have been looking at the code and think I have a starting point on the design.
Remember, the goal here is to be able to create a cache that uses expiration but has no
defined cache size limit. Reading through the code, if ‘-1’ is specified for the eviction
maxEntries, then a ConcurrentHashMap is created and used as the data container and no
eviction is performed. Otherwise a BoundedConcurrentHashMap is created and used as the
data container and eviction is performed according to the specified strategy.
>>
>> Eviction currently appears to happen in two different ways:
>>
>> 1. If an entry is expired, then it can be evicted.
>> 2. If the number of entries in a segment of the cache contains more entries than
“allowed” by the configuration.
>>
>> Here are the modifications that I think need to be made. I have not made any code
mods yet, so I don’t know for sure if this will work. Definitely looking for feedback.
>>
>>
>> Modify configuration in some way so that the following can be specified:
>>
>> The percentage value of used JVM memory (i.e. 95) at which entries should be
evicted to try and avoid an OOM error.
>> The number of items that should be evicted when memory reaches this threshold
>> Modify LRU and LIRS Eviction class so that the accessQueue member can be accessed
by the new Eviction class so that two access queues don’t have to be maintained.
>> Create a new Eviction class, a subclass of LIRS, where the accessQueue is used
from the Eviction strategy the user specifies and the for loop in the execute method is
exited when the evicted set equals value from 1.b above.
>> Modify DataContainerFactory.construct() to call
DefaultDataContainer.boundedDataContainer() regardless of eviction policy. This will
always create a BoundedConcurrentHashMap
>> Create an instance of the new Eviction class in each segment.
>> Modify BoundedConcurrentHashMap.Segment put and replace methods such that when
new values are going to be put into the Segment, the memory usage is checked and the
execute method is called on the new Eviction class.
>>
>> Questions:
>>
>>
>> What are the implications of using a BoundedConcurrentHashMap instead of a
ConcurrentHashMap when maxEntries is set to -1?
>>
>> Thoughts
>>
>>
>> This will not guarantee that an OOM error does not occur. It will attempt to
guard against an OOM caused by putting new values into the cache. This will probably be
more effective when the cache is being used in client/server mode, and less effective when
used in embedded mode as to other code running in the JVM.
>
> --
> Bela Ban
> Lead JGroups / Clustering Team
> JBoss
> _______________________________________________
> infinispan-dev mailing list
> infinispan-dev(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/infinispan-dev
_______________________________________________
infinispan-dev mailing list
infinispan-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev