简体   繁体   中英

If I increase memory heap is it increase GC time

My current application running on 2GB memory Normal GC cycle.

I want to increase JVM memory to 4GB to incrase application performance.

will it incraese GC time? If yes how much performance will get affected. Is their any good artical to tune GC?

Short Answer

Yes, the time will increase. Bigger Heap = Longer Pause Times

Long Answer

There are a few factors to consider. How have you configured your GC to run? how big have you sized your young gen? How often do you see full GC's?

If you rarely see full GC's then the difference will be negligible. If you log your GC activity to log you can see the pause times for a partial GC is very quick. The difference between 2GB and 4GB on a partial GC will be around 0.1s. To log the GC activity you can use the following parameters -XX:+PrintGCDetails -verbose:gc -Xloggc:/log/path/gc.log . There are many tools out there which will read this GC log for you, provide graphs and stats such as throughput and total pause times.

If you are seeing frequent Full GC's and that is why you want to add more memory then you may want to consider profiling the application instead to see what is eating up all the memory. With a bigger heap, these problems will only cause longer GC's until you fix the underlying problems.

In the end you need to try the various configurations, test properly and put into your production environment what will work best for you.

Large heaps == long GC pauses.

I have seen GC stopping for several minutes on ~10G size heaps.

On the other hand, smaller heaps mean more frequent (yet shorter taking) GC cycles. There is no good generic answer to this problem - it all depends on the needs of your app (high-freq trading app? kitten webserver?), hardware, object churn, etc.

Couple of good resources to read on this subject:

There is not straightforward answer because the answer depends on what your application does memory wise.
However, you should take in consideration that if you increase the jvm memory then your application would have more memory... and if all that memory is used then your gc will be called more frequently (increase in GC time)
Increasing the memory is not always the best solution, optimize objects usage and recycling unused object might a better solution.

More available memory will tend to decrease overall time spent in GC but increase the time that a full GC takes. However, modern JVMs don't necessarily use "stop the world" garbage collectors anymore.

Tuning GC of course depends on what JVM you use. The Oracle JVM has a huge amount of GC tuning options and a pretty extensive tuning guide .

If you want to learn how to tune your JVM you can start by reading http://java.sun.com/performance/reference/whitepapers/tuning.html and http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html

Regarding your question there is no simple answer but increasing the heap will both delay the full garbage collection but will also make it last longer.

Performance tuning is a bit of a black art and once you start changing your GC settings it becomes something you need to constantly monitor because in my opinion you are telling the VM that you know better.

There are some VM flags you can add to log the GC pauses and heap sizes which are very useful, you can grep your logs and get some good stats.

verbose:gc -XX:+PrintGCDetails XX:+PrintGCTimeStamps –Xloggc:PATH_FROM_ROOT/gclog.log

Use JVisualVM, Jconsole or a good profiler like JProfiler to monitor. A good place to start to read about GC is

Tuning Garbage Collection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM