InfoQ

News

Deploying a 1 Terabyte Cache using EhCache Server

Posted by Gavin Terrill on Aug 28, 2008

Community
Architecture,
Java
Topics
REST ,
Clustering & Caching
Tags
EHcache ,
Caching ,
JSR 311

Greg Luck, of the EhCache team, announced in early August the availability of SOAP and RESTful APIs for caching. As described in the documentation:

Ehcache now comes with a Cache Server, available as a WAR for most web containers, or as a standalone server. The Cache Server has two APIs: RESTful resource oriented, and SOAP. Both support clients in any programming language.

In a follow up post, Greg outlines his thoughts on deployment options for a theoretical 1 terabyte cache:

The largest ehcache single instances run at around 20GB in memory. The largest disk stores run at 100Gb each. Add nodes together, with cache data partitioned across them, to get larger sizes. 50 nodes at 20GB gets you to 1 Terabyte.

The first, and simplest, approach involves setting up several nodes running  ehcache server and have the client determine the server to use based on an object's hashcode:

String[] cacheservers = new String[]{"cacheserver0.company.com", "cacheserver1.company.com", "cacheserver2.company.com", "cacheserver3.company.com", "cacheserver4.company.com", "cacheserver5.company.com"};
Object key = "123231";
int hash = Math.abs(key.hashCode());
int cacheserverIndex = hash % cacheservers.length;
String cacheserver =cacheservers[cacheserverIndex];

To support redundancy, a load balancer is introduced, and each node runs two ehcache server instances, with replication between them enabled using the existing distributed caching options (RMI or JGroups). In this approach, clients would still determine their servers using the hashcode, but now failures are handled transparently behind the virtual IP assigned by the load balancer.

The third option Greg describes involves moving the responsibility for routing requests to the load balancer.

The RESTful version of the EhCache Server is based on Jersey - the JSR 311 reference implementation. Paul Sandoz, one of the Jersey developers, discussed how the client API of jersey could be used to access the cache for creating and retrieving a sample XML document:

// retrieving a node
Node n = r.accept("application/xml").get(DOMSource.class).getNode();
// creating a node
String xmlDocument = "...";
Client c = Client.create();
WebResource r = c.resource(http://localhost:8080/ehcache/rest/sampleCache2/2);
r.type("application/xml").put(xmlDocument);

So, in what scenarios would a RESTful cache be useful? James Webster reports on seeing an increase in adoption of this architectural style in large enterprises:

An architectural pattern that I have observed a few investment banks implement is a distributed memory cache accessed via a RESTful front-end over HTTP for providing access to market data (e.g.. stock prices, interest rate curves, or derived values like volatility surfaces & correlations) and static data (e.g. counterparty details, settlement defaults). The distributed cache can be ‘easily’ scaled to hold massive data sets and the front-end allows the data to be accessed in a technology agnostic fashion, as long as the client can speak HTTP.

As James points out, it will be interesting to see how long it will take commercial vendors (such as Oracle and Gigaspaces) to support RESTful interfaces in their products.

bug by Greg Allen Posted Aug 28, 2008 6:09 PM
Who would want to expose caching as a service? by Richard L. Burton III Posted Aug 29, 2008 10:20 AM
Re: Who would want to expose caching as a service? by Carlos Zuniga Posted Aug 29, 2008 11:12 AM
Re: Who would want to expose caching as a service? by Gavin Terrill Posted Sep 1, 2008 7:30 PM
Re: Who would want to expose caching as a service? by Zubin Wadia Posted Sep 2, 2008 3:28 PM
REST as opensource project for Gigaspaces by Mathias Kluba Posted Sep 2, 2008 4:01 PM
  1. Back to top

    bug

    Aug 28, 2008 6:09 PM by Greg Allen

    int hash = Math.abs(key.hashCode());

    is not always positive.

    www.blogger.com/comment.g?blogID=33967480&p...

  2. Back to top

    Who would want to expose caching as a service?

    Aug 29, 2008 10:20 AM by Richard L. Burton III

    Why would venders like Oracle or Gigaspaces want to expose caching via SOAP or REST? Caching is not a service; exposing such a 'service' enterprise wide would only lead to problems down the road.

    Best Regards,
    Richard L. Burton III

  3. Back to top

    Re: Who would want to expose caching as a service?

    Aug 29, 2008 11:12 AM by Carlos Zuniga

    They are not saying that caching would be provided as a service by Oracle or Gigaspaces. They are merely pointing out that the services that are provided by these vendors might have RESTful APIs for their clients, in the future. RTFA!


    Carlos

  4. Caching is not a service

    Mark Nottingham's "Leveraging the Web for Services at Yahoo!" talk (QCon London 2007) challenged my idea of what caching could be used for. He explains how HTTP-based caching using Squid has been used to integrate the many Yahoo! properties.

    exposing such a 'service' enterprise wide would only lead to problems down the road

    I'd be interested in hearing about the problems you foresee.

  5. I second Gavin's request - what's wrong with caching as a service?

  6. Back to top

    REST as opensource project for Gigaspaces

    Sep 2, 2008 4:01 PM by Mathias Kluba

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.