Maximum pause-time and throughput garbage collection in Java

1. Introduction

In this tutorial, we’ll discuss two important terms in relation to garbage collection in Java – pause time and throughput. Understanding of these two terms is very important as understanding of these two terms helps in adjusting various parameters related to garbage collection for application performance.

2. Pause time in garbage collection

During the garbage collection process, the garbage collector stops the application for some time and recovers the space that is no longer in use. This pause is called pause time. The goal is always to reduce the maximum duration of these pauses.

The maximum pause-time goal is specified with the command line option -XX:MaxGCPauseMillis=<nnn>. Specifying this option does not mean that the goal will be met definitely. It is possible that the goal is not met at all. It is just a hint to the garbage collector about the goal and that the pause-time of milliseconds or less is desired.

After looking at this parameter, the garbage collector tries to adjust the parameters like heap size to achieve the pause-time goal. In some cases the garbage collector may run more frequently leading to reduction in overall throughput of the application.

3. Throughput goal

Throughput goal is measured in terms of the time spent on garbage collection and time spent outside garbage collection.

During the garbage collection process, the garbage collector spends time at the collection process and the outside the garbage collection process. The time spent outside the garbage collection process is called the application time.

The ratio of the garbage collection time to the application time is 1/(1+nnn).

The throughput time is specified by the option -XX:GCTimeRatio=nnn.

For example, if we specify the goal as -XX:GCTimeRatio=19, it means that the ratio of garbage collection time to the application time is 1/(1+19) = 1/20 or 5% of the total time for garbage collection.

4. Conclusion

In this tutorial, we discussed pause-time and throughput goal. Pause-time is like stop the world thing. It should be short in real-time applications like video games. Throughput goal and pause-time are two important factors which help how to tweak garbage collection parameters according to the nature of the application.