Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Out of memory exception in Server Performance

Category: JMeter

Increasing the heap memory doesn’t fix the outofmemory exception. It might reproduce after sometime.
Increasing the heap size, will improve the response time.
When heap size is increased, GC activities will increase (Minor/Major/Full GC).
When GC activities increases, it suspends all threads for the time GC is running and it impacts the total response time.

To check the default Heap and PermGen sizesRun this command:
java -XX:+PrintFlagsFinal -version | findstr /i “HeapSize PermSize ThreadStackSize”
How to check which GC is running on your system?Run this command:
java -XX:+PrintCommandLineFlags -version
To change from Parallel GC mode to G1GC modeRun this command:
java -XX:+UseG1GC -XX:+PrintCommandLineFlags – version
Garbage collection happens in three phases1. Marking – Marks all the objects which are referenced/reachable
2. Delete / Sweep – deletes all the unreachable objects
3. Compaction – brings the used memory to one side and free to other side
Why should we use G1GCIt will go to either Young, Old or Perm Gen space, whichever is full and performs GC activity.
Serial GCIt is available right from the first version of JAVA.
It is single threaded, Mark and Sweep Collector.
USed for small applications.

Disadvantages:
It pauses all application threads whenever it is working.
It is single threaded.

When should we use Serial GC:
1. It is used for small amount of heap (approx. 100MB)
2. It runs in single thread. It is best suited to single processor machine
3. Application with medium sized to large sized data sets that run on multiprocessor or multithreaded hardware.
Parallel CollectorIt is similar to Serial Collector but multiple threads are used to speedup garbage collection.
Does not kick in until heap is full or almost full.
Stops the world pause when runs.

When should we use Parallel GC:
If peak application performance (throughput) is the priority.
If there are no pause time requirements or pauses of 1 second or longer are acceptable.
Concurrent Mark Sweep (CMS) CollectorIniitial Mark – pauses all application threads. It will identify the live objects which are connected to GC roots.
Concurrent Mark – It identifies objects which are directly or indirectly connected to the initially markd live objects.
Concurrent Preclean – If any new objects created during the above process.
Re-mark – Pauses all application threads. Usually longer than the initial mark.
Sweep – all unreach objects are sweeped.
Concurent Reset – resets the heap memory

Works on old generation.
It works when the old generation is amost 80% full.

Advantages:
very low pause time; as many phases run concurrently with application.

Disadvantages:
It causes heap fragmentation, as there is no compacting phase.

Concurrent mode failure:
If the CMS collector is unable to finish reclaiming the unreachable objects before the tenured generation fills up.
If the CMS is unable to move the objects from young generation to tenured generation and there is no space for this object in tenured generation, this is called concurrent mode failure.

When should we use Serial GC:
If application response time is more important than overall throughput.
If garbage collector pauses must be kept shorter than 1 sec.
G1 GCNew in JAVA 6. Officially supported in Java 7.
G1 is planned as long term replacement for CMS.
G1 supports heaps larger than 4 GB. and is parallel, concurrent and incrementally compacting low pause garbage collector.
With G1, heap is partitioned into a set of equal size heap regions.
A total of approx. 2000 regions, in which each region would be of size 1MB to 32 MB. determined by JVM.

The principle of G1GC is to reclaim the JAVA heap by collecting the region with mostly occupied unreachable objects, hence the name Garbage first.

Evacuation – Live objects are moved from young generation either into survivor regions or old/tenured generation.
Remembered Sets or RSets – track object references into a given region. There is one RSet per region in the heap.
Collection Sets or Csets the set of regions that will be collected in a GC. CSet is evacuated (copied/moved) during a GC. Set of regions can be Eden, Survivor, and/or old generation.

When should we use Serial GC:
1. Large heapsize.
2. Full GC durations are too long or too frequent
3. The rate of object allocation rate or promotion varies significantly
4. Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 sec)

Leave a Reply

Your email address will not be published. Required fields are marked *