JVM Performance

Over the nearly 10 years that we have worked with the Liferay platform, we have had ample opportunity to hone our understanding of how Liferay interacts with the Java virtual machine (JVM), and how to optimally tune the JVM performance for Liferay as a Java application.

Increase JVM Heap Sizing

Out of the box, the Liferay DXP bundle ships with a set of JVM parameters that are well-geared towards development and experimental usage scenarios, but which are not optimal for testing, staging, and production-type environments. One of the first modifications that a well-tuned Liferay environment needs is a change to the default JVM heap sizing. XTIVIA has found that a good starting point for a Liferay implementation in a shared environment is to set the heap size statically at 3 gigabytes, with approximately half of that space used for the young generation, and a 768 megabyte permanent generation. This allows sufficient heap space to allow in-memory caches to operate well, while keeping garbage collection stop-the-world events down to a minimal duration.

To implement this, add or replace the following to the CATALINA_OPTS variable in ${liferay.home}/tomcat-8.0.32/bin/setenv.sh (or ${liferay.home}/tomcat-8.0.32/bin/setenv.bat for a Microsoft Windows environment):

-Xmx3G -Xms3g -XX:NewSize=1536m -XX:MaxNewSize=1536m -XX:MaxPermSize=768m -XX:PermSize=768m

Enable G1GC

Our experience with Liferay has been that garbage collection optimization is a critical part of a well-tuned environment; historically, this has required the use of the concurrent-mark-sweep garbage collection policy, with all of its reliance on fine-tuning to optimize performance. Luckily for us, Liferay DXP version 7.0 has made Java 7 a baseline requirement, which allows us to leverage the far superior G1GC policy developed by Oracle to guarantee superlative performance with a minimum of tuning overhead. At this point, XTIVIA recommends that all of our Liferay implementations leverage the G1GC garbage collection policy; to enable it, add the following to the same CATALINA_OPTS definition in the setenv.sh (or setenv.bat) file referenced above.


If you are using an environment configured with Java 8 (rather than Java 7), add the following to the above statement to leverage String deduplication:


Note that if you enable G1GC, the following JVM settings included above are no longer necessary.


One other change that XTIVIA does recommend is enabling JVM garbage collection logging for all installations; details on this will be included in a later blog post.

Share This