Archive for May of 2009

Some experiences with JBoss Cache as Hibernate second level cache

May 28, 2009
Previously I did some initial setup for JBoss Cache and now I have tested it a little bit on a cluster setup. The setup has two virtual linux images with JBoss 5. In front of them is Apache HTTP for proxying and load balancing.

I started up JBoss on both machines with -c all. This setup has clustering turned on as a default so instances found each other and established JGroup communication channels. Then I deployed the .ear file directly to the deploy directory on each server as the farm deployment did not look too promising. The Apache proxy and balancer were already correctly configured so cookies and sticky sessions worked fine.

The big question is naturally how the performance improved. First I ran a load test without second level caching or query caching in order to have a baseline for comparisons. Then I turned Hibernate second level cache on and executed the same load test. The results were showing around twofold throughput as the average response times halved. I also tried turning on query caching but I did not experience any significant difference with it. Maybe I did not have proper configurations.

I also learned that it is not a good idea to modify data on the DB used by the cluster with Hibernate second level caching on. The nodes communicate sending invalidate messages to each other when data is changed and needs to be refreshed. Modifications outside the cluster mean that the cached data is stale but nodes do not know about it and resulting various errors...

Hibernate second level cache with JBoss Cache 3

May 25, 2009
The project I have been working on lately is a web application running on JBoss 5. The production setup contains a cluster of JBoss instances behind Apache proxy which acts as a load balancer. So far load testing results have been encouraging and load tests also revealed couple bugs.

Our persistence layer is using Hibernate so the next step in caching was to enable Hibernate's second level cache. There are various options but in our clustered environment JBoss Cache was the choice. But getting started with it took some time.

The easiest way is to use 'all' server setup from the JBoss 5 and enable second level cache in Hibernate settings. The JBoss community wiki page provides an example for the setup. Also your JPA entity annotations or mappings need some changes as well because you need to define caching strategy for them.

Taking a look at the documentation of JBoss Cache reveals huge amount of configuration options. Luckily only some of them are relevant for Hiberante second level caching. Be aware that JBoss Cache has been around for some time so some of the older tutorials and blog posts are outdated. At the moment JBoss Cache version 3.x is the recommended one.

In case of caching it is very important to run proper load tests after each configuration modification to verify the performance gain or loss. At the moment I have my test setup running on Apache JMeter. It creates similar load to the server based on historical usage data. Another area of testing is to verify that cluster's caches are having their state updated properly.

I have been experimenting with JBoss Cache only for a day so it will take a bit more time before I can give my opinion or better advices. So, follow my RSS feed to learn more - hopefully soon there will be an update.