Adaptive Size Policy for Best Latency

This section provides a tutorial on how Adaptive Size Policy is used by the Parallel collector to our best latency goal.

According to Java documentation, the Adaptive Size Policy used by the Parallel collector allows you to set 3 performance goals and let the collector to decide the GC configuration to meet those goals.

In this first test, let's ask the Parallel collector to give us the best latency performance using these JVM options:

-XX:MaxGCPauseMillis=1
   We want the best latency:
   Give us the shortest application pause time or < 1 ms.
 
-XX:GCTimeRatio=1
   We don't care about throughput:
   You can spend 50% (or 1/(1+1)) of time doing GC

-Xmx1600m 
   We don't care about footprint:
   You can use as much as 1.6GB heap

Here is what we got:

C:\>\progra~1\java\jdk1.8.0\bin\java -XX:+UseParallelGC    
   -XX:MaxGCPauseMillis=1 -XX:GCTimeRatio=9 -Xmx1200m 
   -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC
   -XX:+PrintGCApplicationStoppedTime    
   -XX:+PrintGCApplicationConcurrentTime
   -XX:AdaptiveSizePolicyOutputInterval=1
   -XX:+PrintAdaptiveSizePolicy
   -XX:+PrintFlagsFinal GarbageCollection2

[Global flags]
    uintx MaxGCPauseMillis                         := 1           
    uintx GCTimeRatio                              := 9           
    uintx MaxHeapSize                              := 1258291200  
...

9999   34340864   10944056   23396808
15.955: Application time: 0.0007244 seconds
   -- The last GC started

    UseAdaptiveSizePolicy actions to meet  *** pause time goal ***
                       GC overhead (%)
    Young generation:       32.40	  (no change)
    Tenured generation:     44.33	  (attempted to shrink)
    Tenuring threshold: (attempted to increase to balance GC costs) = 15
{Heap before GC invocations=3812 (full 1312):
 PSYoungGen      total 4608K, used 4181K [...
  eden space 4352K, 96% used [0x36800000,0x36c15568,0x36c40000)
  from space 256K, 0% used [0x36c80000,0x36c80000,0x36cc0000)
  to   space 256K, 0% used [0x36cc0000,0x36cc0000,0x36d00000)
 ParOldGen       total 28928K, used 18667K [...

15.955: [GC (Allocation Failure) 
AdaptiveSizePolicy::update_averages:  
  survived: 0  promoted: 4194368  overflow: false
AdaptiveSizeStart: 15.957 collection: 3812 
  avg_survived_padded_avg: 0.000000  
  avg_promoted_padded_avg: 5928352.500000  
  avg_pretenured_padded_avg: 0.000000  
  tenuring_thresh: 15  target_size: 262144
PSAdaptiveSizePolicy::compute_eden_space_size: 
   costs minor_time: 0.275430 major_cost: 0.443257 
   mutator_cost: 0.281314 throughput_goal: 0.900000 
   live_space: 286242024 free_space: 8912896 
   old_eden_size: 4456448 desired_eden_size: 4456448
AdaptiveSizeStop: collection: 3812 

[PSYoungGen: 4181K->0K(4608K)] 22848K->22763K(33536K), 0.0014032 secs]
Heap after GC invocations=3812 (full 1312):
 PSYoungGen      total 4608K, used 0K [...
  eden space 4352K, 0% used [0x36800000,0x36800000,0x36c40000)
  from space 256K, 0% used [0x36cc0000,0x36cc0000,0x36d00000)
  to   space 256K, 0% used [0x36c80000,0x36c80000,0x36cc0000)
 ParOldGen       total 28928K, used 22763K [...
  object space 28928K, 78% used [0x04800000,0x05e3aca0,0x06440000)
 Metaspace used 1567K, capacity 2242K, committed 2368K, reserved 4480K
}
15.957: Total time for which application threads were stopped: 0.0019369 s 
10000   34340864   9982800   24358064

Not too bad. The Adaptive Size Policy did a good job:

Last update: 2018.

Table of Contents

 About This Book

 Heap Memory Area and Size Control

 JVM Garbage Collection Logging

 Introduction of Garbage Collectors

 Serial Collector - "+XX:+UseSerialGC"

Parallel Collector - "+XX:+UseParallelGC"

 What Is Parallel Collector

 Parallel Collector GC Log Message Format

 "-XX:+PrintGCTaskTimeStamps" - Print GC Threads

 "-XX:ParallelGCThreads=n" - # of Threads

 Parallel Collector Stops Application for Minor/Major GC

 PSYoungGen Collector Using Tenuring Age

 Parallel Collector Changing NewRatio and SurvivorRatio

 Parallel Collector Adaptive Size Policy

 Adaptive Size Policy Log Messages

 "-XX:+PrintAdaptiveSizePolicy" - Minor GC Report

 Adaptive Size Policy Changed Survivor Space

 Adaptive Size Policy Changed Eden Space

Adaptive Size Policy for Best Latency

 Adaptive Size Policy for Best Throughput

 Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"

 Garbage First (G1) Collector - "+XX:+UseG1GC"

 Object References and Garbage Collection

 Garbage Collection Performance Test Program

 Performance Tests on Serial Collector

 Performance Tests on Parallel collector

 Performance Tests on Concurrent collector

 Performance Tests on G1 collector

 Garbage Collection Performance Test Summary

 Outdated Tutorials

 References

 Full Version in PDF/EPUB