Skip to main content

How to select GC for java application

Which garbage collection(GC) algorithm suite for the application


If you don't have any strict pause-time requirements, first run your application and allow the VM to select a collector.
If necessary, adjust the heap size to improve performance. If the performance still doesn't meet
your performance, then use the specific collector and try.
Performance is dependent on the size of the heap, the amount of live data maintained by the
application, and the number and speed of available processors.
If the recommended collector doesn't achieve the desired performance, then first attempt to
adjust the heap and generation sizes to meet the desired goals. If performance is still
inadequate, then try a different collector: Use the concurrent collector to reduce pause-time,
and use the parallel collector to increase overall throughput on multiprocessor hardware.

Available Collector in Oracle JDK

-XX:+UseSerialGC
-XX:+UseParallelGC
-XX:+UseG1GC
-XX:+UseConcMarkSweepGC
-XX:UseZGC 

How to enable GC logs

Turning on GC Logging in Java 7 / 8

java -XX:+PrintGCDetails -XX:+PrintGCDateStamps - Xloggc: <file-path>

Turning on GC Logging in Java 9 and Up

java –Xlog:gc*:file=<file-path>:filecount=10,filesize=10M

Dynamically Turning on GC Logging in Java 9 and Up

jcmd <pid> VM.log what=gc output=<file-path>

How to analyze GC logs

[0.010s][info][gc] Using G1
[0.028s][info][gc] Periodic GC disabled
[0.584s][info][gc] GC(0) Pause Young (Normal) (G1 Evacuation Pause) 23M->4M(130M) 3.386ms
[0.885s][info][gc] GC(1) Pause Young (Normal) (GCLocker Initiated GC) 38M->6M(130M) 3.475ms
[1.782s][info][gc] GC(2) Pause Young (Concurrent Start) (Metadata GC Threshold) 77M->8M(130M) 3.816ms
[1.782s][info][gc] GC(3) Concurrent Cycle
[1.789s][info][gc] GC(3) Pause Remark 9M->9M(40M) 2.746ms
[1.791s][info][gc] GC(3) Pause Cleanup 9M->9M(40M) 0.043ms
[1.792s][info][gc] GC(3) Concurrent Cycle 9.942ms
[2.141s][info][gc] GC(4) Pause Young (Normal) (G1 Evacuation Pause) 27M->10M(40M) 5.106ms
[2.404s][info][gc] GC(5) Pause Young (Normal) (G1 Evacuation Pause) 29M->11M(40M) 2.537ms
[2.628s][info][gc] GC(6) Pause Young (Normal) (G1 Evacuation Pause) 29M->12M(40M) 3.846ms

This is an example of a CG log file , reading and analyzing this text file is a tedious task. There are some tools available for log analysis.

Comments

Popular posts from this blog

is not a JMX compliant Standard MBean

I got the fallowing exception and issue solved. If your are using MBean , MBean Interface and Implementation should be in same package, Otherwise use MXBean. javax.management.NotCompliantMBeanException: MBean class comlanka.rest.controller.DataManagerController does not implement DynamicMBean, and neither follows the Standard MBean conventions (javax.management.NotCompliantMBeanException: Class comlanka.rest.controller.DataManagerController is not a JMX compliant Standard MBean) nor the MXBean conventions (javax.management.NotCompliantMBeanException: comlanka.rest.controller.DataManagerController: Class comlanka.rest.controller.DataManagerController is not a JMX compliant MXBean)         at com.sun.jmx.mbeanserver.Introspector.checkCompliance(Introspector.java:176)         at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:317)         at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)        

AWS amplify hugo App build specification amplify.yml

 I needed a content-oriented site with solely static content for a little project I'm working on, so Hugo was an obvious choice. I looked into using AWS Amplify to host it, But the default amplify.yml not working for me and can't find the correct build file, I have modified the amplify.yml to build the Hugo cms. Hope this is helpful, Please comment. version : 1 frontend : phases : build : commands : - npm install - npm run build:webpack && npm run build:hugo artifacts : baseDirectory : dist files : - '**/*' cache : paths : []

hamcrest and junit java.lang.NoSuchFieldError: NONE

Issue - When you using hemcrest with JUnit5 you may get  java.lang.NoSuchFieldError: NONE error. Solution - Add junit-vintage-engine to classpath           <dependency>             <groupId>org.junit.vintage</groupId>             <artifactId>junit-vintage-engine</artifactId>             <version>5.3.1</version>             <scope>test</scope>         </dependency>  Full Exception - java.lang.NoSuchFieldError: NONE at org.hamcrest.DiagnosingMatcher.matches(DiagnosingMatcher.java:12) at org.hamcrest.beans.SamePropertyValuesAs.hasMatchingValues(SamePropertyValuesAs.java:63) at org.hamcrest.beans.SamePropertyValuesAs.matchesSafely(SamePropertyValuesAs.java:31) at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55) at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12) at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8) at com.codegen.ShopTest.testExtern