This article has participated in the weekend learning program, click the link to see more details :juejin.cn/post/696572…

Parallel avenge

The Parallel Scavenge collector is a new generation collector that uses the mark-copy algorithm, the Parallel Avenge collector, and looks similar to the ParNew insane. The Parallel Collector is characterized by its focus being different from the others.

  • The FOCUS of the CMS collector is to minimize the pause time of user threads during garbage collection,

    • The shorter the pause time, the better the application that needs to interact with the user, the better the response speed can improve the user experience.
  • The goal of the Parallel Insane is to achieve a controlled Throughput.

    • Throughput is the ratio of CPU time spent running user code to total CPU consumption, i.e. Throughput = time spent running user code/(time spent running user code + garbage collection time). If the virtual machine runs for 100 minutes and garbage collection takes 1 minute, the throughput is 99%.
    • High throughput can efficiently use THE CPU time, as soon as possible to complete the operation of the program, mainly suitable for the background operation without too much interaction.

The Parallel Avenge: The collector provides several parameters to control throughput precisely, one for maximum garbage collection downtime

-xx :MaxGCPauseMillis: The allowed value of the parameter is a number of milliseconds greater than 0, and the collector will do its best to ensure that the memory reclamation time does not exceed the set value.

  • However, don’t assume that if you set this parameter to a slightly smaller value you will make the system garbage collection faster, the GC pause time will be reduced at the expense of throughput and new generation space: The system changed the size of the new generation to 300MB faster than 500MB, which directly caused the garbage collection to happen more frequently, instead of 100 ms pauses every 10 seconds, it now happens every 5 seconds and 70 ms pauses. Pause times did go down, but so did throughput. (Because of the increased frequency of recycling).

-xx :GCTimeRatio: The value of this parameter should be an integer greater than 0 and less than 100. It is the ratio of garbage collection time to total time, which is equivalent to the inverse of throughput. If you set this parameter to 19, the maximum allowed GC time is 5% of the total time (1 / (1+19)), and the default is 99, which is the maximum allowed garbage collection time of 1% (1 / (1+99)).

The Parallel Avenge collector is also often referred to as a “through-first” collector due to its affinity for throughput.

– XX: + UseAdaptiveSizePolicy: A switch parameter, when the parameters are opened, there is no need to manually specify the size of the Cenozoic (Xmn), Eden and Survivor area ratio (- XX: SurvivorRatio), promotion of age old s (- XX: PretenureSizeThreshold) detail parameters, such as, The virtual machine collects performance monitoring information based on the current system performance and adjusts these parameters dynamically to provide the most appropriate pause times or maximum throughput. This adjustment mode is called GC Ergonomics.

If the reader is not familiar with the collector operation and manual optimization is difficult, use the Parallel Scavenge avenge in conjunction with the adaptive adjustment strategy and hand off the memory management tuning to the virtual machine is a good choice.

Just set the basic memory data (such as -xmx for maximum heap), and then set an optimization target for the virtual machine using the MaxGCPauseMillis parameter (which is more concerned with maximum pause times) or GCTimeRatio (which is more concerned with throughput). The virtual machine can adjust the details. The adaptive adjustment strategy is also an important difference between the Parallel Avenge collector and the ParNew collector.