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.

 

  1. Modify configuration in some way so that the following can be specified:
    1. The percentage value of used JVM memory (i.e. 95) at which entries should be evicted to try and avoid an OOM error.
    2. The number of items that should be evicted when memory reaches this threshold
  2. 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.
  3. 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.
  4. Modify DataContainerFactory.construct() to call DefaultDataContainer.boundedDataContainer() regardless of eviction policy. This will always create a BoundedConcurrentHashMap
  5. Create an instance of the new Eviction class in each segment.
  6. 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:

 

  1. What are the implications of using a BoundedConcurrentHashMap instead of a ConcurrentHashMap when maxEntries is set to -1?

 

Thoughts

 

  1. 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.

 

 

-- Dave Marion


 

From: manik@jboss.org
Date: Tue, 11 Jan 2011 11:46:40 +0000
To: infinispan-dev@lists.jboss.org
Subject: [infinispan-dev] Poor man's size-based eviction Re: ISPN-863

Hi Dave

Just saw that you signed the contributor agreement.

So yeah, what you may want to look into is the EvictionManager [1] which will periodically have its processEviction() [2] method called.  This doesn't actually do any evictions here (named so for legacy reasons) since the current data container is self-sizing/evicting.  However it is still periodically invoked to purge expired entries.  

You can piggyback on the same invocation to test upper and lower bounds of memory utilisation (if enabled), but the bit that I still think you need to figure out is deciding which entries to evict, and how many of them to evict.

Cheers
Manik

[1] https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java
[2] https://github.com/infinispan/infinispan/blob/master/core/src/main/java/org/infinispan/eviction/EvictionManagerImpl.java#L84

On 10 Jan 2011, at 11:08, Manik Surtani wrote:

Excellent, Dave.

You should probably come up with a design first - or maybe a prototype on your fork of the project on GitHub - and post it here for comment.

Cheers
Manik

On 8 Jan 2011, at 00:34, david marion wrote:

Manik,
 
I am on the list. I will start getting my dev environment setup according to instructions on site.
 
Dave Marion
  _______________________________________________
infinispan-dev mailing list
infinispan-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev



_______________________________________________
infinispan-dev mailing list
infinispan-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev

--
Manik Surtani
manik@jboss.org
twitter.com/maniksurtani

Lead, Infinispan
http://www.infinispan.org




_______________________________________________ infinispan-dev mailing list infinispan-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/infinispan-dev