简体   繁体   中英

Garbage Collection - Changing Collector Algorithm

We are running our Spring+Hibernate web app on Tomcat (Java 1.5). Currently we use 2GB of heap space (I am told it is the max possible on Solaris 32 bit servers although Server has a total of 16GB RAM). The current JAVA_OPTS are :

-XX:MaxPermSize=512m -XX:+UseParallelGC -Xms2048m -Xmx2048m

The Young Gen + Survivor space is ~600 MB and Old Gen is 1.4 GB.

There are time when the memory gets full and we need to restart Tomcat. The following are the observations:

  1. In approx 16 hour active running of the server, the GC spends around an hour for MarkSweep (~300 collections - Old Gen) and 5 - 7 minutes on Scavenging (~1500 collections - Young Gen).
  2. There are times when the Old Gen get full in 10 minutes and we need to restart the server. Identifying the thread that is causing is has not been very successful

We would like to change to the following JAVA_OPTIONS - I need feedback on whether this is sensible choice (UAT environments do not match the load of Prod env and we are unable to replicate the same in UAT)

  1. Add -Xmn1024m - This is to make sure that the Young Gen objects don't easily get promoted to Old Gen. Any suggestions on increasing / decreasing this ? Also this would lead to more Young Gen GC and lesser Old Gen GC.

  2. -XX:+UseParallelOldGC - This is to make the Young and Old Gen GC run multiple threads so that they gets GCed quicker.

  3. Is the limitation of 2GB applicable to Solaris Servers too ? Cant the heap be increased to more than 2GB ?

Please share your thoughts on the above.

Thanks, Midhun

If you experienced too long major collections pause you should consider use -XX:+UseConcMarkSweepGC (and also keeping the -XX:+UseParallelOldGC ) in order to perform GC concurrently.

The fact you use -Xms2048m -Xmx2048m can be a bad idea, if those values are not quite good you don't let the JVM scales them (but if your sure no problem). In Java Performance Tuning 2nd Ed. 5 frequent suggestion are made about heap size :

  1. Set the starting heapsize the same as the max heap size
  2. Set the starting size to the size needed by the max number of alive objects and set the max to 4 times this amount
  3. Set the starting heap to max heap size
  4. Set the starting heap size between 1/10 and 1/4 the max heap size
  5. Use the default initial heap size

(Try to find the best for you)

This doc give good advice to resolve GC issue , read carrefully paragraphe about Generation Size Adjustments and try some of the command to print your GC activity, some of them can really be helpful to see some bottlenecks in your app or in your GC config.

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