Simple Performance Improvement with Large Ehcache Disk Store Data Sets

April 29, 2010

One of my applications has several millions cacheable entries.  In order to cache as much as possible without going back to the database I use both a  memory store and a disk store in my Ehcache configuration.  Loading a serialized item from disk is still faster than loading from a database generally.  That being said I was running into performance issues due to the constant reads and writes to and from the disk store.   Due to the serialized nature of the data file it would block on subsequent accesses resulting in lag and performance issues.  So, how did I address it?  I decided to partition the single cache into multiple caches.  So, rather than using something like:

ehcache.getRegion(CONSTANT).get(id);

I now use:

ehcache.getRegion(CONSTANT + (id % 10));

I now have 10 different cache regions resulting in less concurrent access and better performance.  A very simple trick when you have extremely large data sets.  Remember, partitioning is always your friend regardless of what type of data you use.

UPDATE: This is being done in Ehcache 1.5.0…I understand there are better improvements in Ehcache 2.x, so please consult the documentation for more information.

3 Responses to “Simple Performance Improvement with Large Ehcache Disk Store Data Sets”

  1. Just wondering what version of ehcache your running where this is needed. I’d be curious to know if it’s still needed in 2.1 beta.
    Cheers,
    steve

  2. Steve,

    This was tested against Ehcache 1.5, which I have been using for quite some time unfortunately. I have not taken the time to upgrade. I am very interested in what 2.1 offers to improve this though. Feel free to email me at nicholas dot hagen at znetdevelopment dot com.

    Thanks,
    Nicholas Hagen

  3. Simple Performance Improvement with Large Ehcache Disk Store Data Sets…

    One of my applications has several millions cacheable entries. In order to cache as much as possible without going back to the database I use both a memory store and a disk store in my Ehcache configuration. Loading a serialized item from disk is still…

Leave a Reply