JVM 调优总结

1.避免FullGC:

  1.调整堆中新生代和幸存代大小,避免因为幸存代不足而让Minor GC后的对象进入老年代。每次Minor GC都有对象进入老年代会造成数次MinorGC后FullGC.

  2.减少永久区浪费,JVM进程启动完毕后,永久区变化不大了,这时可以参看Perm是否有剩余空间,节省Perm区的空间分给新生代用。

缩短单次MinorGC所用时间:选择合理的GC算法,并进行GC算法参数调整。比如 低交互性可使用Parallel Scavenge(这种不会尽可能缩短GC时间)

2.tomcat调优

(1) 查看gc统计结果

[hotspot@bogon ~]$ jstat -gcutil 3553 | column -t
S0     S1    E      O      P      YGC  YGCT    FGC  FGCT   GCT
10.28  0.00  90.07  91.12  51.75  838  60.922  1    1.728  62.650

从结果看出,虽然经历了838次MinorGC,但仅发生了1次 FullGC,成功避免了FullGC

(2)查看JVM参数

[hotspot@bogon ~]$ jinfo -flags 3553
Attaching to process ID 3553, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.5-b02

-Djava.util.logging.config.file=/home/hotspot/tomcat7_8082/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms500m -Xmx800m -XX:PermSize=256M -XX:MaxPermSize=300M 
-Djava.endorsed.dirs=/home/hotspot/tomcat7_8082/endorsed -Dcatalina.base=/home/hotspot/tomcat7_8082 -Dcatalina.home=/home/hotspot/tomcat7_8082 -Djava.io.tmpdir=/home/hotspot/tomcat7_8082/temp

 (3)成功tomcat调优案例

[hotspot@bogon ~]$ jinfo -flags 25493
Attaching to process ID 25493, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 23.5-b02

-Djava.util.logging.config.file=/home/hotspot/tomcat7b/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
-XX:+UseG1GC -XX:+UnlockCommercialFeatures -Xms800m -Xmx800m -XX:MaxTenuringThreshold=12 -XX:MaxGCPauseMillis=200 -XX:InitiatingHeapOccupancyPercent=45 -XX:SurvivorRatio=6 -XX:PermSize=250M -XX:MaxPermSize=400M
-Djava.rmi.server.hostname=172.16.11.52 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9110 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
-Djava.endorsed.dirs=/home/hotspot/tomcat7b/endorsed -Dcatalina.base=/home/hotspot/tomcat7b -Dcatalina.home=/home/hotspot/tomcat7b -Djava.io.tmpdir=/home/hotspot/tomcat7b/temp [hotspot@bogon ~]$ jstat -gcutil 25493 5s 1 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 100.00 4.96 54.33 69.55 1166 247.260 0 0.000 247.260

从jstat的结果看出,FGC没有发生过。

3.ecilpse调优

jdk 1.7.0_17  | win10 64bit | cpu 3.0 | ram 8g | hd 1t 

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20150204-1316
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
#### 该行以下为调优参数 ####
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:+DisableExplicitGC -Xmn550m -XX:SurvivorRatio
=6 -Xms1024m -Xmx1024m -XX:MaxPermSize=400m -XX:PermSize=300M -XX:MaxTenuringThreshold=12 -Declipse.p2.max.threads=20

-XX:+DisableExplicitGC : 禁止在程序在使用System.gc() 这个方法会引发FullGC,为了让关闭后的窗体不再占用堆内存, eclipse程序中自动调用了System.gc()

-XX:MaxTenuringThreshold=12:让需要进入老年代的对象尽快进入

调优结果:startup:6s loadup:12s openPomXml:3s

原文地址:https://www.cnblogs.com/zhengwenqiang/p/7298256.html