Java development generally involves JVM tuning, of which GC tuning is a key item. So what exactly is gc tuning tuning about? Specifically, the business. The following is a discussion on this topic

The cause of

Why is it business? Start from cc++ if it is c/c++ to do the development of the effect is relatively stable. After all, without gc there is no such thing as an unresponsive pause caused by GC. But C/C ++ development is slower than Java, especially cross-platform applications that require constant macro definition to differentiate systems. There are fewer open source libraries and frameworks than Java as a whole. There are so many frameworks in Java that you can say that if you’re dealing with a more established business, basically the application of the Java framework doesn’t have to start all over again. So Java development efficiency brings great convenience.

The downside of Java is its garbage collection. Java does not have a delete operation to free memory, which is a bit less of a memory leak problem to worry about. His endgame is a garbage collector. This causes a brief pause before the JVM does object collection.

business

Despite the above issues, business scenarios are really diverse and tuning for business scenarios is what we’re going to do. Business scenarios can be divided into the following categories

task-based

Interactive type

task-based

Task-based is basically executing a piece of code without much interaction once it’s executed. For example, if you compute a month’s worth of data and so on, most of the behavior is to compute the results and then you want to run out of the results and the part of Java that you care about is throughput. Throughput is business execution time/GC time + business execution time.

-xx :GCTimeRatio the formula is 1/1+N and the default value is 99, which means that the throughput gc takes up 1% of the time and the remaining 99% of the time is business execution.

Interactive type

The interactive type is generally manifested in our website, which requires people to participate. In this case, the response speed is important. If the JVM pauses for 5 seconds after gc, this is obviously not acceptable.

CMS is generally preferred. The advantage of CMS is that when the old band is recycled, the multiple steps only initial marking and re-marking are STW. The remaining steps do not cause JVM business to pause because the GC thread and the business thread are running in parallel and the response is not as good as it would be without GC.

The problem with CMS is that floating garbage eventually takes a single thread collection and in the old days there was a single collection that took a long time.

G1 alleviates the problem of CMS floating garbage by using region to manage heap object allocation. The G1 also has fullGC issues. It also needs to be reasonably avoided.

Special case

For example, parallel GC does not necessarily perform worse than CMS in an interactive scenario where the whole heap is paused but the heap is small and the number of GC threads is large. QPS measures better than CMS.

To observe the way

The initial gc options are now available and it is time to adjust the gc parameters for the specific combinations. An observer is needed to see if the adjustment is valid. There are a number of alternatives that Prometheus proposed and the main thing about Prometheus is that it’s open source and it’s simple to build and you can type out all of the metrics that you refer to through Grafana. So we can look at the graphs and so forth and get a little bit of a sense of what’s going on with the parameters and instead of looking at the graph in the log it’s a little bit more intuitive in terms of the detail in the log but it’s really not intuitive in terms of the timelines.

summary

Gc tuning involves analyzing business resources and selecting a combination of garbage collectors and then comparing the details of various GC parameters and supporting parameters through monitoring such as Prometheus.