Ehcache and Terracotta for the Enterprise Caching Solution

Ehcache logo
Performance always becomes priority one after the proof of concept, no matter how hard we argue to refactor the prototype. But we as developers adapt and move forward. So your system produces an output, of course there are enhancements you could make to this process, but the biggest enhancement will be to cache the outputs for every user following the poor soul who endures the cache miss. So the task is made and assigned to you, what do you use?

There exists plenty of options, and this is not to say that Ehcache is the silver bullet to all caching solutions. This is to say Ehcache and Terracotta can make a great enterprise solution that you can be proud to implement (and its easy).

Ehcache has tens of settings, that all have defaults, and to be honest, “it just works.” Heres how Ehcache works:

Cache cache = this.manager.getCache("myDataCache");
Element element = new Element("myContentKey", mySerilizableObject);
cache.put(element);

Cache cache = this.manager.getCache("myDataCache");
Element element = cache.get("myContentKey");
Serializable value = element.getValue();

Looks pretty much like a map right? You can replace all of those hashmap caching nearly one for one with some simple wrappers to these methods (which Ehcache also offers).

That easy and you can manage huge heap apps.

Now how do you manage this in a clustered environment? Just as easy: Terracotta. Terracotta is the suggested cluster solution to Ehcache. Download Terracotta, install it on your server, setup some scripts to keep it running and that’s all you need to know. After setting up a configuration defining all the servers in the cluster, and the design desired (mirrored, or distributed arrays), you point your Ehcache config to the terracotta config, and your done. No code changes, no drastic setup, no dredging through tens of exceptions when trying to connect the two, it just works!
This is how I explained to my management how confidant I felt after installing Terracotta and prototyping its use:

[quote]I installed it and it just worked, I don’t feel comfortable with this product at all.[/quote]

We are supposed to spend hours working through all the exceptions and updating our classes to get these things to work. So when everything fell into place, I felt like it was just going to break as soon as it went into production.

    • Terracotta has been the easiest enterprise solution I have ever integrated. We have learned some things since then:
  • When changing object structures, old cached objects need to be cleared.
  • JMX integration requires a non standard lib which can be difficult to integrate into popular JMX monitoring solutions, however not impossible.
  • Ehcache garbage collection can be a challenge, however there are lots of settings to try and optimize your JVM.

[hr]

Useful References:
[ilink url=”http://ehcache.org/documentation/garbage_collection.html” style=”info”]Tuning Garbage Collection[/ilink]
[ilink url=”http://ehcache.org/documentation/configuration.html” style=”info”]Ehcache Configuration[/ilink]
[ilink url=”http://www.terracotta.org/documentation/3.1.x/product-documentation-15.html” style=”info”]Terracotta Server Array Configurations[/ilink]

[hr]

Update: This past year (2010) Ehcache released “Big Memory.” Though I have yet to try Big Memory, with the reviews read, and my experience with these products, I bet the performance is even greater.
[ilink url=”http://terracotta.org/bigmemory” style=”note”]Big Memory Home[/ilink]

Post to Twitter Post to Delicious Post to Facebook Post to Reddit

Loading Disqus Comments ...