Thursday, March 22, 2012

OpenCMIS Class Loading Behavior

Ever tried OpenCMIS client in any web applications and observed performance issues with that. I did find that recently using OpenCMIS 0.4 version with my web application deployed in Tomcat 6. The issue I faced was classes loaded were kept on growing and looks like it was never garbage collected even after stopping that particular application. The free tool VisualVM was used to analyse this along with jmap and jhat utils from jdk 1.6 to see the strong references which never gets unreachable. With these tools it was clearly evident that even after redploying the particular web application, references of the loaded classes were not removed.

The in-depth analysis to the problem helped me to learn some nuances of class loading mechanism. Thanks to the problem and thought of sharing the same here.

Some reasons that could cause this problem:

1. Frequent offenders are scripting languages, dynamic proxies (including the ones generated by application servers)

2. Custom class loaders that don't carefully free up older classes after loading new ones

3. Also, Tomcat container holds the reference for the opencmis classes(specifically JAXB static references) and cleanup never happens. This cold be a limitation running CMIS code from JSP/Servlets.

4. Heavy use of Proxy classes, which are created during run time

5. Just like Hibernate, OpenCMIS creates and loads new classes on the fly at run time, and thus drawing heavily on the (possibly non-heap allocated) method area of the JVMs memory space. The behavior is expected in case of on the fly created classes. When application is not generating classes on the fly, the number of loaded classes and amount of permgen should be more or less static.


Finally, the solution which worked out in my case:

1. Added -XX:+CMSPermGenSweepingEnabled -XX:MaxPermSize=128m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC to JAVA_OPTS in catalina.bat
2. Replaced jaxb-impl2.2.1 wih version 2.2.3 jars jaxb-impl.jar and jaxb-api.jar

Other problem I have observed here is whenever the testui web application stopped from tomcat console, web application class loader does not unload CMIS JAXB classes because of which we see memory leak likely to happen message. Here we have not much control or it is not recommended to tweak the class loader functionality. Instead just stop and restart Tomcat.

No comments:

Post a Comment