How to reduce crash while java mode and excessive gc

In Java, parallel mode failure means that the parallel collector could not free up enough memory space and the long-term genealogy, and it should refuse and allow gc to stop completely. very expensive.

I understand this concept, but I never had a good understanding of A) what can lead to failure in parallel mode and B) what solution ?.

This confusion leads me to write / debug code without any hints, and often I have to buy performance from Foo to Bar around these flags for no particular reason, just have to try.

I would like to learn from the developers, how is your experience? If you encounter such a performance problem, what is the reason and how did you solve it?

If you have any coding recommendations, please do not be too general. Thank!

+43
java garbage-collection concurrency
May 27 '10 at 2:32
source share
4 answers

The first thing I learned about CMS is more memory than other collectors, which is 25-50% a good starting point. This will help you avoid fragmentation, as the CMS does not make any consolidations, such as stopping global collectors. Secondly, do what helps the garbage collector; Integer.valueOf instead of the new Integer, get rid of anonymous classes, make sure that inner classes do not have access to inaccessible things (private in the outer class). The less trash, the better. FindBugs, as well as ignoring warnings, will help a lot.

Regarding customization, I found that you need to try a few things:

-XX: + UseConcMarkSweepGC

Tells the JVM to use CMS in the extended gen.

Correct the size of your heap: -Xmx2048m -Xms2048m This prevents things such as expanding and shrinking the heap from executing the GC.

-XX: + UseParNewGC

use a parallel rather than a serial meeting in the younger generation. This will speed up your small collections, especially if you have a very large young gene set up. A large young generation is usually good, but not more than half the old size.

-XX: ParallelCMSThreads = X

set the number of threads that the CMS will use when they do what can be done in parallel.

-XX: + Note CMSParallelRemarkEnabled is serial by default, this can speed up the process.

-XX: + CMSIncrementalMode allows applications to run more by passing GC between phases

-XX: + CMSIncrementalPacing allows the JVM to display the change in how often it collects over time

-XX: CMSIncrementalDutyCycleMin = X Minimum amount of time spent executing the GC

-XX: CMSIncrementalDutyCycle = X Start by executing the GC this% of the time

-XX: CMSIncrementalSafetyFactor = X

I found that you can usually get a low pause if you tune it so that it basically gathers. Since most of the work is done in parallel, you get mostly regular predictable pauses.

-XX: CMSFullGCsBeforeCompaction = 1

It is very important. He tells the CMS collector to always fill the collection before she starts a new one. Without this, you may encounter a situation where it removes a bunch of work and starts again.

-XX: + CMSClassUnloadingEnabled

By default, CMS will allow your Permigent to grow until he kills your application in a few weeks. It stops it. Your PermGen will only grow if you use Reflection or abuse String.intern or do something bad with the class loader or a few other things.

The ratio of survivors and ownership of them can also be reproduced, depending on whether you have long or short-lived objects and how much the object copies between the survivors with whom you can live. If you know that all your objects will adhere to, you can set the size of the survivors to zero, and everything that is saved in one collection of young people will be immediately transferred.

+22
Oct 19 '11 at 20:50
source share

Quote from Understanding Parallel Logs for Garbage Collectors Labeling

A concurrency error can be avoided by increasing the generation size or by initiating a CMS collection with less load on the heap by setting CMSInitiatingOccupancyFraction to a lower value

However, if the application does have a memory leak, you just buy time.

If you need a quick restart and recovery, and you prefer the "fast way", I would suggest not using CMS at all. I would stick with '-XX: + UseParallelGC'.

From "Ergonomics of the Garbage Collector"

The parallel garbage collector (UseParallelGC) throws an exception in memory if an excessive amount of time has been spent collecting a small amount of heap. To avoid this exception, you can increase the heap size. You can also specify the parameters -XX:GCTimeLimit=time-limit and -XX:GCHeapFreeLimit=space-limit

+11
May 27 '10 at 12:44
source share

Sometimes OOM is pretty fast and killed, sometimes a long gc period suffers (the last time was more than 10 hours).

It seems to me that a memory leak is at the heart of your problems.

CMS failure will not (as I understand it) cause OOM. Rather, the failure of the CMS is due to the fact that the JVM needs to do too many collections, and the CMS could not keep up. One of the situations where many data collection cycles take place over a short period is when your heap is nearly full.

For a very long time, the GC sounds weird ... but theoretically possible if your car crashed terribly. However, a long period of repeated GCs is plausible if your heap is nearly full.

You can configure the GC to refuse when the heap 1) at maximum size and 2) is still close to full after completing the full GC. Try this if you have not already done so. It will not cure your problems, but at least your JVM will quickly get OOM, which will allow you to restart and restore the service faster.

EDIT - option -XX:GCHeapFreeLimit=nnn , where nnn is a number from 0 to 100, which gives the minimum percentage of heap that should be free after GC. The default value is 2. The option is listed in the label "The most comprehensive list of options -XX for Java 6 JVM . " (There are many -XX options listed there that do not appear in the Sun documentation. Unfortunately, the page provides some information about what the options actually do.)

You should probably start looking for if your application / webapp has a memory leak. If so, your problems will not go away if these leaks are not found and fixed. In the long run, messing around with options. Hotspot GC will not fix memory leaks.

+3
May 27 '10 at 4:55 a.m.
source share

I found that using -XX:PretenureSizeThreshold=1m in order to make the β€œlarge” object immediately moved into space significantly reduced my young GCs and crashes in parallel, as it does not try to reset the number of survivors + 1 remaining in living ( xmn=1536m survivorratio=3 maxTenuringThreashould=5 ) until the completion of the full CMS cycle. Yes, my space for survivors is large, but about once every 2 days something comes in the application that he needs (and we launch 12 application servers every day for 1 application).

0
Nov 05 2018-11-11T00:
source share



All Articles