Jelastic Garbage Collection Agent

Currently JVM does not have any feature to call full GC periodically. Releasing reserved, but at the same time unused RAM by JVM to OS is required for automatic vertical scaling, configured in Jelastic Cloud. That’s why Jelastic uses a special Garbage Collection agent.

Note: Jelastic GC agent implements smart algorithm of the consumed and free RAM monitoring. While processing monitoring outcomes, it recognizes the possibility to release a portion of RAM to OS that results in calling Full GC. If JVM does not have free RAM which can be released to OS, then Jelastic GC agent does not call Full GC. That brings the possibility of app performance degradation to zero.
Jelastic GC agent works only for two kinds of Garbage Collection (set in Jelastic by default):
  • -XX:+UseParNewGC
  • -XX:+UseG1GC

If you change the default GC settings to any other which does not provide shrinking and can not release RAM to OS by design, then Jelastic GC Agent will be disabled and won’t call Full GC.

To tune the settings of Jelastic GC agent, navigate to the server > variables.conf file for Tomcat, TomEE or Jetty application server.

GC agent for GlassFish can be configured or disabled via the GlassFish admin panel in gfcluster-config > JVM Settings > JVM Options.

Enable/Disable Jelastic GC Agent

Jelastic GC agent is enabled for all newly created Java application servers by default.

If you want to enable Jelastic GC agent in already existing containers, you need to upload the jelastic-gc-agent.jar file and set the agent manually in the following way:

1. Download the jelastic-gc-agent.jar file.

2. Navigate to the Conf files of your Java server and upload the downloaded .jar file to the home folder.

3. Navigate to server > variables.conf file and state the path to your jelastic-gc-agent.jar file in the Java agent parameter. The path can differ based on the Java server you use:
  • Tomcat/TomEE: /opt/tomcat/temp
  • GlassFish: /opt/glassfish3/temp
  • Jetty: /opt/jetty/home

4. Save the changes and Restart the server.

If you think that Jelastic GC agent processes may cause performance degradation for your application, please comment the following line and restart the server:


Change the Period of Checks

By default, Jelastic GC agent initiates system checking every 15 minutes (beginning from every JVM start) to force freeing of unused application memory. The period of checks can be changed based on your requirements.

To change the time period of checks, specify the duration between calls of full GC in seconds, as shown below:


Save your edits and Restart the server to apply the changes.

Enable Debug Mode

You can also enable debug mode in the following way:


As a result, you’ll be able to track GC processes in the logs.

Note that you can use both custom settings (changed period of checks and enabling debug) together:


Save your changes and Restart the server.

Check GC Results

To check the result of the configured periodical checks and RAM releasing you can use a special Loader application.

1. Follow the link to download Loader.war archive with the testing application.

2. Upload this .war archive to the Jelastic Cloud.

3. Deploy this Loader application to the environment with the Java application.

4. Open Config files and navigate to server > variables.conf file in order to check the Jelastic Java agent settings.

In our case, we changed the period value to 60 seconds to get a faster result.

If you also edit the configurations, then do not forget to Save the changes and Restart the server.

5. After that, open the application in a browser and add the following parameters to the link:


6. Now you can navigate to the Statistics where after some time you’ll see the results.

When you request the application, the memory usage increases by 500 MB due to the parameters added to the app link. Such an amount of RAM is going to be used during 300 seconds (also due to stated parameter).

And after that, the memory usage will decrease as the Jelastic Java agent calls Full GC. This is performed because the Jelastic GC agent recognizes the possibility to release some RAM as the app completed its active processes and does not require the full amount of memory.

You can request the testing application again in order to load the memory several times and check the process of its release.

7. As we switched on the debug mode for our Java agent, we can also track the process in the Log files.

The amount of available free memory (in bytes) can be seen in the catalina logs

Hence, using this method, you can improve your application memory management which will lead to a reduction of RAM consumption by JVM. As a result, you will save your money and increase the performance of your application. Enjoy!