Java garbage collection is the process by which Java programs perform automatic memory management. This post, we’ll explain how to add the log in the Platform.sh application.
How to Generate GC Log File?
In order to understand the GC log, you first need to generate one. Passing the following system properties to your JVM would generate GC logs.
To set the JVM log on Platform.sh we need to append it with the Java startup parameter.
E.g., To define the GC log. From your app’s .platform.app.yaml file.
web: commands: start: java -jar -Xmx2048m -Xlog:gc*=debug:stdout:time,uptimemillis,tid target/microprofile-microbundle.jar --port $PORT
When you append the GC log, the next step is to check the information, the default file to the registry is on
/tmp/log/app.log. Therefore you can check the GC information from the command below once you’re inside the application container.
tail -f /tmp/log/app.log
To access the machine through ssh, please check the PSH documentation:
The flag -XX:+PrintGC (or the alias -verbose:gc) activates the “simple” GC logging mode, which prints a line for every young generation GC and every full GC.
If we use -XX:+PrintGCDetails instead of -XX:+PrintGC, we activate the “detailed” GC logging mode which differs depending on the GC algorithm used. We start by taking a look at the output produced by a young generation GC using the Throughput Collector.
Unified JVM Logging
Java 9 comes with a unified logging architecture (JEP 158) that pipes a lot of messages that the JVM generates through the same mechanism, which can be configured with the -Xlog option.
By default the GC log is written to stdout. With -Xloggc: we may instead specify an output file. Note that this flag implicitly sets -XX:+PrintGC and -XX:+PrintGCTimeStamps as well. Still, I would recommend setting these flags explicitly if desired, in order to safeguard yourself against unexpected changes in new JVM versions.
Migrate to Java 11
The benefits of using the latest LTS version are the increase of support to the containers, therefore, beyond the new APIs and security fixes, there is an increase of performance to run on GC.
D Command-Line Options
This appendix describes some command-line options that can be useful when diagnosing problems with the Java HotSpot VM.
- Java Memory arguments: https://community.platform.sh/t/java-memory-commands/481