When it comes to the memory management of a software application, garbage collection is crucial. Actually, the memory of unused or unreferenced objects is recovered by a Java program called Garbage Collector. It means that, like other Java codes, the GC executes when a certain condition, such as memory fullness, is met. GC affects the system’s overall performance by using some CPU and memory resources while it is running, although only slightly. Therefore, the Garbage Collection shouldn’t happen too soon or too late. A delay in GC cycles results in memory leakage, whereas too many GC cycles reduce system performance and increase CPU usage.
Now, the question is what metric can show the depth of impact if GC also affects the application’s performance?
And the answer is Throughput.
Throughput in Garbage Collection
Let’s understand the definition of Throughput in terms of Garbage Collection.
Definition:
The amount of productive work completed by the application in a specific duration of time is known as Application Throughput.
Formula:
Application Throughput (X) = 100 – (Total time spent for GC/Total Time Window * 100)
Refer to the below image, it shows the duration of the productive work and garbage collection.
Let’s calculate the GC throughput:
Garbage Collection Duration: 3 + 4+ 3 = 10 seconds
Total Duration Window: 3600 seconds
Applying the formula: Application Throughput = 100 – (10/3600*100)
=> Application Throughput = 100 – 2.78
=> Application Throughput = 99.72%
Important Points:
- The higher the throughput percentage, the better the application performance.
- The high value of throughput impacts latency and memory footprint.
- Application Throughput with respect to GC can be obtained by uploading the GC log file to any GC log reader tool like gceasy, gcviewer etc.
- A Parallel Garbage Collector is also called a Thoughtput Collector. You can set target throughput using the argument -XX:GCTimeRatio=<N>
Example: If you set N = 24 then you can achieve 96% application throughput.
How to calculate -XX:GCTimeRatio?
Formula:
XX:GCTimeRatio (N) = [100 / (100 – X)] – 1
where X is application throughput.
Throughput shown by GC Viewer
You may be interested: