Java_Garbage_Collector

Download Report

Transcript Java_Garbage_Collector

G1 TUNING
Shubham Modi(10327729)
Ujjwal Kumar Singh(10772)
Vaibhav(10780)
Motivation

There is memory sensitive application which is running and now a new object
has to be created. Suppose that the memory heap has insufficient space for
the newly created objects. Such conditions would trigger a full garbage
collection cycle, which will perform compaction of the heap.

With CMS GC, the full collection is serial and STW, hence your application
threads are stopped for the entire duration while the heap space is reclaimed
and then compacted.

This affects the performance of the application and will decrease the
responsiveness and throughput.
G1 Garbage Collector

G1 is a compacting collector i.e. it compacts sufficiently to completely avoid
the use of fine-grained free lists for allocation, and instead relies on regions.

The heap is partitioned into a set of equal-sized heap regions, each a
contiguous range of virtual memory providing greater flexibility in memory
usage.
[6]
How G1 works?

Heap is split into many fixed size region ranging from 1 to 32 Mb
[6]

Regions are mapped into Eden,
Survivor and Old generation
[6]
 This is a STW pause. Eden and
Survivor size is calculated for the
next GC. GC Pause time is taken into
consideration.
[6]

Live objects have been evacuated to
survivor regions or to old generation
regions
[6]
 Liveness of regions is calculated
and empty regions are marked X
and are deleted in remark phase
[6]
[6]
[6]

After calculating liveness of regions
G1 selects the region with least
liveness and collects it. Both young
and old generation are collected at
the same time.

After it we get compacted dark blue
and dark green regions
Why G1?

Provide predictable GC pause duration

Decrease frequency of Stop The World(Full GC Cycle)

Compact free space without lengthy GC induced pause times

Do not require much larger Java heap space

Do not sacrifices throughput of application

Compaction mostly eliminating the fragmentation issues
Objectives

Improves responsiveness

Increase throughput
Problem
root
child1
child2
child3
………
Child
5million

When we try to create 10 million children of root, it gives OutofHeap Error

We created first tree with root and 5 million children occupying ~ 55% of heap
space

Then we made child1 as root of tree

Therefore all other nodes becomes unreachable

Then we created another tree with a root and its 5 million children

Hence Garbage collector is called to free the space causing Stop The World
event to occur
Factors affecting G1 Performance

GC Pause Time: Set the target for the maximum GC pause time(soft goal)

Heap Occupancy: Percentage of the entire heap occupancy to start the
concurrent GC cycle(Default 45)

Old Generation size: New to Old Generation size ratio(Default 2)

Heap region size: Size of the single region of uniformly divided space(Min 1
and Max 32Mb)
Results
Here we achieved high
responsiveness with average
GC pause time as 0.010 sec
which is normally 0.1 sec
Here we achieved high
throughput 35% which is
normally 25-27% in other cases.
As shown in this case we
skipped Stop The World event
 Grey region shows concurrent GC pauses of an application
 Dark grey region shows Stop The World event
Tools used

Eclipse for generating Tree

GCViewer to get plots and other details of G1 performance like throughput
etc.
References

[ 1 ] Domani, Tamar, Elliot K. Kolodner, and Erez Petrank. "A generational onthe-y garbage collector for Java." ACM SIGPLAN Notices. Vol. 35. No. 5. ACM,
2000.

[ 2 ] www.cubrid.org/blog/dev-platform/understanding-java-garbagecollection

[ 3 ] www.ibm.com/developerworks/library/j-leaks

[ 4 ] www.cubrid.org/blog/textyle/428187

[ 5 ] www.infoq.com/articles/JavaGarbageCollectionDistilled

[6]
www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStart
ed/index.html

[ 7 ] github.com/chewiebug/GCViewer/blob/master/README