Performance and price are two big considerations in application hosting that always matter. And, often, we question ourselves on how to decrease the spends, without affecting the performance of your apps at the same time. In this article, we’d like to address automatic memory management for Java applications hosted with Jelastic using garbage collection.
Let’s clarify what garbage collection is, what it does for Java applications and how it works within Jelastic PaaS.
Garbage Collection is a form of automatic memory management. Its aim is to find data objects in memory that are no longer demanded and make their space available for reuse.
The created object uses some memory that remains allocated until there are references for the use of the object. When there are no references for an object, it is considered to be no longer required and the memory occupied by the object can be reclaimed. In such a way, you don’t pay for unused resources and can cut your costs.
We’ve tested different kinds of Garbage Collectors (GC) and defined the most appropriate ones for the Java applications hosted in our cloud, taking into consideration the automatic vertical scaling that CirrusGrid provides. As a result of our investigations, we adjusted the default settings of Garbage Collectors in CirrusGrid in order to increase the benefits for our users.
CirrusGrid supports the following GCs:
Tip: The Openj9 Java engine does not support the GCs listed above. The following options are available for the Openj9 instances instead:
By default CirrusGrid PaaS uses G1 GC for JVM 8+ versions. For lower versions it employs the ParNew GC. Also, for JVM versions below 12 CirrusGrid attaches jelastic-gc-agent.jar which enables vertical scaling for older releases.
For JVM 12+ versions, the platform provides integrated vertical scaling to ensure G1 triggering with the following pre-set container variables:
You can always check current settings of your Java process by executing ps -ax | grep java. You will see something like this:
/usr/java/libericajdk-12.0.1/bin/java.orig -server -XX:G1PeriodicGCSystemLoadThreshold=0.6 -XX:G1PeriodicGCInterval=900k -XX:+UseStringDeduplication –XX:+UseG1GC -Xmaxf0.3 -Xminf0.1 -Xmx1638M -Xmn30M -Xms32M -jar jelastic-helloworld-1.1.war
Also CirrusGrid automatically configures the following parameters:
If JVM version is higher than 12, the platform additionally configures the following Java options:
For more details, you can review the following script that manages automatic configuration of the Java options.
If you believe that customization of default settings can improve performance or memory consumption, you can tune them according to the requirements of your application. We recommend customizing these configurations only if you fully understand the impact of such changes on your application behaviour.
You can set a custom GC parameter based on your application requirements via Environment Variables (please do not mix them with Java options).
Alternatively, all these parameters can be passed to Java process via variables.conf in the container.
All of the paths to config, executable or log files can differ based on the Java server you use and can be accessed via Configuration File Manager or SSH.
Java Application Server Name
Path to variables.conf
Tomcat/TomEE
/opt/tomcat/conf/variables.conf
GlassFish
/opt/glassfish/glassfish/domains/domain1/config/variables.conf
Spring Boot
/home/jelastic/conf/variables.conf
WildFly
/opt/wildfly/conf/variables.conf
Payara
/opt/payara/glassfish/domains/domain1/config/variables.conf
SmartFoxServer
/opt/repo/versions/2X/SmartFoxServer_2X/SFS2X/config/variables.conf
or
/opt/shared/smartfox/2X/SmartFoxServer_2X/SFS2X/config/variables.conf
Java Engine
Jetty
/opt/jetty/etc/variables.conf
/opt/shared/conf/etc/variables.conf
1. Open Conf files to configure your Java server.
2. For Tomcat, navigate to the opt > tomcat > conf > variables.conf file.
-XX:+UseShenandoahGC
As a result of properly configured options, the GC can be observed in action via the Statistics tab.
That’s it!
Powered by BetterDocs
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.