Ehcache 1.4, which is nearing completion, adds some user requested features such as ExceptionHandler(s). These are implemented in ehcache as dynamic proxies. One todo I have had is to investigate the performance degradation from use of same. An article by Brian Goetz (fellow JSR107 member) on IBM developerworks a few years ago predicted a 2x cost.
I have done some testing using a memory only cache in ehcache and come with a line ball. For ehcache afficianados, the test is in CacheTest.testProportionMemoryAndDiskPerformance. This is a test that protects against regression in ehcache by asserting outside times for variations in memory and disk store sizes. I added a memory only test using the new CacheExceptionHandler dynamic proxy.
It does 5000 puts and gets, sleeps for 500ms to give the hotspot compiler a chance to optimise, and repeats 10 times. Then it does the same for a dynamic proxy.
INFO: Time for MemoryStore: 120
Aug 19, 2007 5:10:52 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 123
Aug 19, 2007 5:10:53 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 63
Aug 19, 2007 5:10:53 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 40
Aug 19, 2007 5:10:54 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 128
Aug 19, 2007 5:10:55 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 30
Aug 19, 2007 5:10:55 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 131
Aug 19, 2007 5:10:56 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 29
Aug 19, 2007 5:10:56 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 35
Aug 19, 2007 5:10:57 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 35
Aug 19, 2007 5:10:57 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for MemoryStore: 130
Mean: 86ms
Aug 19, 2007 5:10:58 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 69
Aug 19, 2007 5:10:59 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 46
Aug 19, 2007 5:10:59 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 91
Aug 19, 2007 5:11:00 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 158
Aug 19, 2007 5:11:00 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 69
Aug 19, 2007 5:11:01 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 51
Aug 19, 2007 5:11:02 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 137
Aug 19, 2007 5:11:02 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 39
Aug 19, 2007 5:11:03 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 45
Aug 19, 2007 5:11:03 PM net.sf.ehcache.CacheTest testProportionMemoryAndDiskPerformance
INFO: Time for exception handling MemoryStore: 38
Mean: 74ms
The result is that I cannot detect a performance differnece.
Maybe the reason is that ehcache just passes the requests on unless they throw an exception. We have
try {
invocationResult = method.invoke(ehcache, args);
} catch (Exception e) {
In Java 5 at least the cost seems to be negligle, even with an in-memory cache.