Tuning notes the young generation and the old age

Tuning the young generation and the old age (notes finishing)

Several common noun

Generation Young (Young region)
from the young generation space (including Eden and Survivor region) is referred Minor GC reclaim memory
space is too small they may lead directly into the old region. If the old district is full, it will trigger the full gc. But not too large, too General Assembly caused the recovery takes too long, resulting in blocking the application.

Years old (old district)
from the old GC called Major GC's
space is too small will produce small fragments of old district, does not fit large objects, causing frequent full gc. If the cache, old area must be properly bigger, while the cache should not grow indefinitely.

Survival Zone (Survivor)
raison d'etre of Survivor, is to reduce the object was sent to old age, thereby reducing the occurrence of Full GC.

Eden (Eden)
throughout the heap memory (heap) = young + old

GC (garbage collection)

Heap area has two Survivor areas, new objects will survive in the Eden. Eden District will lead a young GC area if there is not enough space.

After experiencing a MinorGC, Eden live objects in the first block will be moved to the survivor space-S0, Eden is cleared at this time;

Eden and other areas filled again, would then trigger a Minor GC, Eden, and S0, the live objects are copied into the second block will survivor space-s1; Eden case is emptied and S0, S1 and S0 and at a swap roles.
If space is insufficient or Survivor of experience 16 times Minor GC can survive in the new generation of the object will be sent to the old year by allocating guarantee mechanism.

Let's responsible for allocating guarantee old Survivor objects that can not fit directly into the old era. If the remaining space is smaller than the size of the object transfer, the direct FullGc

 

Enter old age objects

  • Large objects directly into the old year (to avoid frequent copy)
  • In the long-term program to hold a reference to an object (target age reaches a specified threshold value will be entered years old)
  • survivor area is too small, can only enter the old year

FullGC

Execution Minor GC (the young generation GC) time, JVM checks to see if the old era largest contiguous free space is larger than the total size of all current new generation of objects
If so, then executed directly Minor GC (the young generation GC) (this time is executed no risk)
is less than, JVM checks to see if the open space allocation guarantee mechanism, if not open directly into an Executive Full GC
if the guarantee mechanism is turned on, the JVM will check whether old's largest contiguous free space is larger than the previous promotion to the old the average size of the era, and instead perform Full GC is less than the execution
Full GC if more than will be executed Minor GC (the young generation GC), if Minor GC (the young generation GC) fails will be executed

Full GC often occur when accompanied by at least one of the Minor GC, but not absolute. Major GC generally slower than the speed of more than 10 times Minor GC

 

Memory overflow

Only old's lack of spatial phenomena appear only when the object into the new generation and created large object, large arrays. When space is still insufficient after the implementation of Full GC, it will throw the following error:
java.lang.OutOfMemoryError: the Java heap Space

 

The reason full GC frequent

  • Object reference not released the long-term
  • survivor area is too small
  • old area is too small

Full GC tuning approach
1: Let the object is recovered in the Minor GC stage, so that objects in the new generation of multi survive for some time and do not create too large an array of objects and

2: the young generation of small objects as much as possible, as large objects directly into the old era. Because the young generation algorithm using the markers to copy recovered memory, fast

3:Eden区如果没有足够的空间时会引发一次young区的GC,通过-XX:SurvivorRatio 进行调整 Eden 和 Survivor 比例大小。少量对象的存活,适合复制算法(年轻代),大量对象存活,适合标记清理或者标记压缩(年老代)。

 

调优建议

  • (单服务器单应用)最大堆的设置建议在物理内存的1/2 到 2/3 之间
  • survivor和伊甸园的最优比例为1:8。年轻代=eden+2survivor
  • 年轻代和老年代的最优比例为1:2。

 

 

Guess you like

Origin www.cnblogs.com/Zfc-Cjk/p/11534654.html