Greg Luck's Blog

I am sick of simple. Things should be great!

Browsing Posts in Ehcache

This is the first in a series of webinars which will explore Caching Principles.

You will learn how to assess the effect that caching to a given performance situation and be able to calculate the performance improvement. Further it will be shown how to tune caches for maximum effectiveness.

This webinar focus on non-clustered caching principles.

The following topics are covered:

- What exactly is caching.
- Locality of Reference, Data lifespans and reuse patterns
- Pareto Distributions
- Amdahl’s Law
- Cache Statistics

Click to watch.

A few weeks ago I blogged about the fantastic tc-maven plugin which works just as well as the Jetty plugin and makes life easy for Maven-based developers. My surveys from talks I do suggest that the mix of Maven and Ant based builds is 40-60% Maven. Three years ago it was about 10% Maven. Interestingly in Philadelphia the maven usage was 40% versus 60% in San Francisco. But many Ant people have tried Maven and had a less than stellar experience. My own experience was that Maven was as painful as EJB ever was. But it has been getting better over time.

The forthcoming release of Ehcache bundles the Terracotta server and I am very interested in making this as easy as possible for developers. The 2.1-beta kit has instructions for using the tc-maven plugin. The upcoming 2.1 final will also support Ant. Fortunately Ant and Maven interoperate and we will support Ant via the Maven Ant Tasks library.

Installation

Install Maven

Download and install Maven which is just expanding the download somewhere on your file system. Version 2.2.1 or higher is required.

Installing Maven Ant Tasks

There are a couple of choices documented at the Maven site. For simplicity, download the Maven Tasks for Ant 2.1.0 and copy the jar into your $ANT_HOME/lib directory.

Create a pom.xml

Maven requires a pom.xml which is placed in the same directory as build.xml. Use this sample which has all you need:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-terracotta</artifactId>
<version>2.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.terracotta.maven.plugins</groupId>
<artifactId>tc-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<id>run-integration</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-integration</goal>
</goals>
</execution>
<execution>
<id>terminate-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>terminate-integration</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>terracotta-snapshots</id>
<url>http://www.terracotta.org/download/reflector/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

Additions to build.xml

Add these to build.xml:

    <macrodef name="maven">
        <attribute name="options" default=""/>
        <attribute name="goal"/>
        <attribute name="basedir"/>
        <attribute name="resultproperty" default="maven.result"/>
        <element name="args" implicit="true" optional="true"/>
        <sequential>
            <java classname="org.codehaus.classworlds.Launcher" fork="true"
                  dir="@{basedir}" resultproperty="@{resultproperty}">
                <jvmarg value="-Xmx512m"/>
                <classpath>
                    <fileset dir="${maven.home}/boot">
                        <include name="*.jar"/>
                    </fileset>
                    <fileset dir="${maven.home}/lib">
                        <include name="*.jar"/>
                    </fileset>
                </classpath>
                <sysproperty key="classworlds.conf" value="${maven.home}/bin/m2.conf"/>
                <sysproperty key="maven.home" value="${maven.home}"/>
                <arg line="--batch-mode @{options} @{goal}"/>
            </java>
        </sequential>
    </macrodef>

    <property name="maven.home" value="/Users/gluck/work/apache-maven-2.2.1"/>

    <target name="start_terracotta" description="Starts the Terracotta Server">
        <maven basedir="${basedir}"
               goal="tc:start"
               resultproperty="maven.build.result"
                />
    </target>

    <target name="stop_terracotta" description="Stops the Terracotta Server">
        <property name="maven.home" value="/Users/gluck/work/apache-maven-2.2.1"/>
        <maven basedir="${basedir}"
               goal="tc:stop"
               resultproperty="maven.build.result"
                />
    </target>

Ensure you change your maven.home property value to where you installed Maven.

Usage

Starting Terracotta Server

ant start_terracotta
Buildfile: /Users/gluck/work/ehcache/core/build.xml

start_terracotta:
     [java] [INFO] Scanning for projects...
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Building Unnamed - test:test:jar:1.0
     [java] [INFO]    task-segment: [tc:start]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] [tc:start {execution: default-cli}]
     [java] 2010-05-01 12:34:26,737 INFO - Terracotta 3.2.1, as of 20100304-100300 (Revision 14673 by cruise@su10mo5 from 3.2)
     [java] 2010-05-01 12:34:27,018 INFO - Configuration loaded from the Java resource at '/com/tc/config/schema/setup/default-config.xml', relative to class com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.
     [java] 2010-05-01 12:34:27,152 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Starting DSO Server
     [java] [INFO] [dso start] 2010-05-01 12:34:27,576 INFO - Terracotta 3.2.1, as of 20100304-100300 (Revision 14673 by cruise@su10mo5 from 3.2)
     [java] [INFO] OK
     [java] [INFO] [dso start] 2010-05-01 12:34:28,065 INFO - Configuration loaded from the Java resource at '/com/tc/config/schema/setup/default-config.xml', relative to class com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.
     [java] [INFO] [dso start] 2010-05-01 12:34:28,255 INFO - Log file: '/Users/gluck/terracotta/server-logs/terracotta-server.log'.
     [java] [INFO] [dso start] 2010-05-01 12:34:30,759 INFO - Available Max Runtime Memory: 506MB
     [java] [INFO] [dso start] 2010-05-01 12:34:30.575::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
     [java] [INFO] [dso start] 2010-05-01 12:34:30.620::INFO:  jetty-6.1.8
     [java] [INFO] [dso start] 2010-05-01 12:34:30.663::INFO:  Started TerracottaConnector@0.0.0.0:0
     [java] [INFO] [dso start] 2010-05-01 12:34:33,097 INFO - JMX Server started. Available at URL[service:jmx:jmxmp://0.0.0.0:9520]
     [java] [INFO] DSO Server status: OK
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] BUILD SUCCESSFUL
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Total time: 14 seconds
     [java] [INFO] Finished at: Sat May 01 12:34:33 EST 2010
     [java] [INFO] Final Memory: 22M/133M
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] [dso start] 2010-05-01 12:34:33,840 INFO - Terracotta Server instance has started up as ACTIVE node on 0.0.0.0:9510 successfully, and is now ready for work.

BUILD SUCCESSFUL
Total time: 17 seconds

The Terracotta server will be running on its default port of 9510.

Stopping Terracotta Server

ant stop_terracotta
Buildfile: /Users/gluck/work/ehcache/core/build.xml

stop_terracotta:
     [java] [INFO] Scanning for projects...
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Building Unnamed - test:test:jar:1.0
     [java] [INFO]    task-segment: [tc:stop]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] [tc:stop {execution: default-cli}]
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Stopping DSO Server
     [java] [INFO] [dso stop] No host or port provided. Stopping the Terracotta server instance at 'localhost', port 9520 by default.
     [java] [INFO] OK
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] BUILD SUCCESSFUL
     [java] [INFO] ------------------------------------------------------------------------
     [java] [INFO] Total time: 7 seconds
     [java] [INFO] Finished at: Sat May 01 12:48:37 EST 2010
     [java] [INFO] Final Memory: 21M/123M
     [java] [INFO] ------------------------------------------------------------------------

BUILD SUCCESSFUL
Total time: 10 seconds

More Information

The Terracotta plugin is documented on the Forge.

I am interested in people’s experiences using this. Ping me at gluck AT gregluck.com or post questions to the Ehcache Forum.

This year, on Friday 24 September, straight after JavaOne, Terracotta is hosting a one day conference focused on Scale in San Francisco. Called @Scale it will be all about learning from experts on how to scale enterprise apps in traditional deployment and in several cloud environments.

We don’t yet have session details but he have got a killer list of speakers. They include:

  • Greg Luck, CTO of Ehcache
  • Ari Zilka, CTO/Founder of Terracotta
  • Simon Crosby, CTO of the Data Center and Cloud Division of Citrix
  • Jeff Barr, Web Services Evangelist of Amazon.com
  • Dr. Rich Wolski, CTO/Founder of Eucalyptus
  • Adrian Cole, Founder of jclouds.org
  • James House, Founder of Quartz
  • Dan Querna, Founder of Cloudkick
  • Jos Boumans, Engineering Manager for Ubuntu Server of Canonical
  • Darin Pope, Principal Consultant of PlanetPope, Inc.

This is a unique opportunity to get all these speakers under one roof for an intense 8 hours of deep immersion in Scale.

The cost is only USD200 but there is an early bird special of USD150 which is available now.

Register for @Scale

Having servers at development time is pain. You need tooling to make it smooth. Fortunately, Terracotta has the tc-maven plugin for this purpose.

Integration Testing with Maven

To start and stop the server pre and post integration tests, add the following to your pom.xml:

<pluginRepositories> <pluginRepository> <id>terracotta-snapshots</id> <url>http://www.terracotta.org/download/reflector/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories>   <plugin> <groupId>org.terracotta.maven.plugins</groupId> <artifactId>tc-maven-plugin</artifactId> <version>1.5.1</version> <executions> <execution> <id>run-integration</id> <phase>pre-integration-test</phase> <goals> <goal>run-integration</goal> </goals> </execution> <execution> <id>terminate-integration</id> <phase>post-integration-test</phase> <goals> <goal>terminate-integration</goal> </goals> </execution> </executions> </plugin>
 

Interactive Use

Interactively, with the pom configured, it is just mvn tc:start to start and mvn tc:stop to stop

Rubbing the bull's nose

Being full time with Terracotta gives me an opportunity to engage with the Ehcache community like never before.

For example I just came back from two weeks in the US. I gave talks in San Francisco, Philadelphia, New York and Atlanta, this last at DevNexus. Here are the details of that tour.

Tour Dates

In May and June I will be hitting the road again. Tour dates so far:

Date     | Location           | Event              | Topic

13 May| Sydney               |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

2 June | San Francisco | Google JUG | Ehcache Google App Engine module and caching in GAE generally

2 June | Jacksonville    |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

2 June | Tampa               |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

15 June | France             |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

16 June | Franfurt           |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

17 June | Amsterdam     |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

18 June | Sweden            |               JUG | Scaling Hibernate and DAOs and Ehcache 2.0; New stuff

Sunrise over the Flat Iron Building, New York City

Topics Flexible

Most people are interested in scaling Hibernate which most of the talks cover. But I am flexible. If you are interested in attending one of these events send me some topic requests to gluck AT gregluck.com.

For example, I learnt on my last tour that around 45% of shops are using JDBC usually with a DAO layer. Because I always use ORM and have been doing that for 7 years this caught me by surprise. Caching DAOs offers the same benefits as Hibernate second level caching. We are developing some new docs on ehcache.org and sample code to show how to do this. So I am going to include that in my next lot.

Another popular topic is Ehcache versus Memcached. Comparing and contrasting the two is a great way to understand what is on offer with Ehcache, particularly in combination with Terracotta.

Other News

There has been a lot going on. Ehcache 2.0 was released a few weeks ago. Ehcache is doing some interesting integrations with Grails, Google App Engine and EC2. Plus there have been new releases of the RESTful server. And next week some bug fix releases coming: ehcache 2.0.1  ehcache-web 2.1.

Finally we will be likely be making some packaging refinements to make it much easier to get Ehcache with Terracotta integrated into your development process. Terracotta is a server. We will probably add Maven and Ant tooling support so that you easily deploy it locally for running integration tests. It’s startup time is 5 seconds which is pretty quick and compares favourably with things like Tomcat and ActiveMQ.

Ehcache Server and Standalone Server have been released to Sourceforge Downloads. The server provides RESTful and SOAP APIs to Ehcache. It is available as a WAR which works with all app servers, or standalone using Glassfish V3 embedded.

New in this release is integration with Terracotta Server Array for coherent, scalable and HA caching. Also the Ehcache core has been upgraded to version 2.0, Jersey to 1.1.5, Metro to 2.1.5 and for standalone, Glassfish to V3 embedded.

This release has been performance tested against memcache and gives comparable over-the-network performance. Coupled with the simplicity of coding in your HTTP client of choice in your programming language of choice and easily getting the benefits of Terracotta Server Array backing it, this is a killer combination.

See the Ehcache Server documentation to get started or download it now.

Due to an issue with external repository handling, these have not yet been released to Maven. Sonatype are completing a project for Sun whereby they will be adding their artifacts to the Central repository. This is expected to be completed this week or next, so the Maven artifacts will be released then.

Interestingly, it can take a little bit of work to tune your Java HTTP client for speed. The following code snippet shows two recommended optimisations for the Apache HTTP client: turning off the staleness check (you would catch the exception on connection clone in production code and open a new one) and ignoring cookies.

HttpClient httpClient = new HttpClient();
httpClient.getParams().setParameter("http.connection.stalecheck", false);
for (int i = 0; i < cacheOperations; i++) {
    String url = new StringBuffer(cacheUrl).append('/').append(keyBase).append(i).toString();
    HttpMethod httpMethod = new GetMethod(url);
    httpMethod.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    httpClient.executeMethod(httpMethod);
}
LOG.info(cacheOperations + " gets: " + stopWatch.getElapsedTime() + "ms");

Deciding upon the best caching solution can be complicated. Some questions are:

  • Which one offers the best performance?
  • Which provides the highest availability?
  • Which scales most effectively?
  • Which is best for persisting large datasets?
  • How can I guarantee that data is consistent for all users?
  • Which is best for Java applications?
  • Which is best if you have a non-Java client?

This short webcast, to be held on April 15, 2010 at 11 am PDT,  will provide insight into these important topics and others by comparing the two leading open source caching solutions: Ehcache and Memcached.

Not only will you gain a better understanding of the differences between Ehcache and Memcached, you will also learn a lot about improving application performance and scalability from one of the world’s foremost authorities: Ehcache founder, Greg Luck.

Please register for the WebEx even if you are unable to attend and you will get an email with a link to the recording.

I am doing some JUGs and a SIG in the US the first two weeks of March. And a JUG next Monday in Brisbane, Australia.

The topics will vary from JUG to JUG but will have for most JUGs:

  • Demo: How to configure Pet Clinic for use with Ehcache standalone and Ehcache EX with Terracotta Server Array
  • Tuning tips
  • Ehcache 2.0 new and notable
  • Demo: Ehcache Monitor preview

Here are the JUG details:

  • Date: Monday 15 February 2010
  • Time: 6:00-7:30 pm
  • Location: Toowong Library, Brisbane
  • Event: Queensland Java Users Group
  • Speaker: Greg Luck and Paul O’Keefe


  • Date: 2 March 2010
  • Time: 6:30-9:00 pm
  • Location: 650 Townsend Street, San Francisco, CA 94107
  • Event: The San Francisco Java User Group Special Event
  • Speaker: Greg Luck
  • URL: [http://www.sfjava.org/calendar/12432040/]


  • Date: 3 March 2010
  • Time: 7:00-9:00 pm
  • Location: The Omnicare Building, 630 Allendale Rd, King of Prussia PA 19406
  • Event: Philly JUG
  • Speaker: Greg Luck
  • URL: [http://phillyjug.jsync.com/]


  • Date: 4 March 2010
  • Time: 6:30-9:30 pm
  • Location: Liquidnet Inc, 498 Seventh Avenue, 15th floor, New York, NY 10018
  • Event: NY Java SIG
  • Agenda: Ehcache in the Cloud
  • Speaker: Greg Luck
  • URL: [http://www.nyjavasig.com/]


  • Date: 8 March – 9 March 2010
  • Time: 8am to 6pm and 8 am to 4pm
  • Location: Cobb Galleria Centre, Two Galleria Parkway, Atlanta, Georgia 30339
  • Event: DevNexus Atlanta
  • Speaker: Greg Luck
  • URL: [http://www.devnexus.com/]
  • Date: 11 March 2010
  • Time: 6:30-9:30 pm
  • Location: 650 Townsend Street, San Francisco, CA 94107
  • Event: The San Francisco Java User Group Special Event
  • URL: [http://www.sdforum.org/]

I am giving a webcast next week. There is lots going on with Ehcache right now with new features. We have some impressive numbers to show off too.

In this webcast learn how to use Terracotta Ehcache to get dramatically boost application performance. Terracotta Ehcache provides a high performance Hibernate second level cache that boosts application performance as much as 10x.

Understanding performance behavior specific to your application can be a challenging task. Every application workload is unique. To provide reliable metrics for comparison, Terracotta Ehcache has benchmarked the Spring PetClinic reference application against competitive solutions such as Memcached, Commercial IMDG, My SQL and a leading In Memory Data Grid including the impressive performance increases from the latest Terracotta 3.2 Server Array.

Sign up here: https://terracotta.webex.com/terracotta/onstage/g.php?t=a&d=661974937