Monitor Liferay cache behaviour with JConsole

A crucial point for any project is the use of cache strategies, especially when you try to implement a project the first time on a new infrastructure. Therefore I will give some hints  how you can easily get confident with our ootb caching strategies.

So lets get started with my prerequisites.

You download any tomcat bundle of liferay, I used 606 our latest community edition of the portal with tomcat 6.

As JConsole needs to connect to tomcat you will need to give tomcat some extra configuration. I added the necessary opts to catalina.sh (on windows that would be catalina.bat) somewhere near line 257.

(I have my catalina.sh stored in 606workspace/bundles/tomcat-6.0.29/bin)

 

CATALINA_OPTS="$CATALINA_OPTS \

-Dcom.sun.management.jmxremote \

-Dcom.sun.management.jmxremote.port=12345 \

-Dcom.sun.management.jmxremote.ssl=false \

-Dcom.sun.management.jmxremote.authenticate=false"
 
CATALINA_OPTS="$CATALINA_OPTS \ -Dcom.sun.management.jmxremote \ -Dcom.sun.management.jmxremote.port=12345 \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false"

 

Now we need to tell liferay that we would like to evaluate the ehcache statistics. We need an entry in portal-ext.properties for that, as this costs a small portion of performance it is disable be default.

 

My portal-ext.properties file is stored in /606workspace/bundles/portal-ext.properties, where bundles is the directory which includes tomcat*/bin

 

 #
 # Set this to true to enable Ehcache statistics.
 #
ehcache.statistics.enabled=true

 

So much for the setup, we can start the portal now (exec startup.sh in a shell or double click startup.bat on windows in tomcat bin folder)

 

Once the Portal is started go forth an create some WebContent in Liferay CMS and put the article on any page.

On my end I just used

http://localhost:8080/web/guest/home

and placed a Web Content Display Portlet on the page which used one content I have created earlier.

Screenshot from my browser on http://localhost:8080/web/guest/home with a web content display portlet

 

So now we can start jconsole from shell or commandline by typing in

jconsole

hit enter and it starts rightaway, as long as you have a full jdk installed.

JConsole has a startup screen

JConsole StartupScreen

 

We will choose org.apache.catalina... to connect to tomcat and directly land on the overview page in jconsole. To look at the cache hits we navigate to MBeans and then on the left tree we will walk following path.

net.sf.ehcache/CacheStatistics/liferay-multi-vm

Then you will have a lot of classes inside this container, which represent the caches of different entities etc., as we want to monitor the statistics of rendered journal content, the following class is what you want to find:

com.liferay.portal.kernel.dao.orm.EntityCache.com.liferay.portlet.journal.model.impl.JournalArticleImpl

Once you have discovered the class unravel the details by clicking on it and select

Attributes

 

JConsole Explorer view with Journal selected

 

Now the cache statistics overview will show up and every time you refresh your browser on 

http://localhost:8080/web/guest/home

the statistics will change.

Jconsole monitor snippet looking at a rendered journal cache

 

Have fun exploring

Blogs
Only one improvement suggestion: Add the CATALINA_OPTS to setenv.sh / setenv.bat. Create the file if it isn't there (but it is contained in Liferay's tomcat bundles). This file will survive a tomcat update as it's not contained in tomcat itself and so you can easily isolate your from tomcat's changes.