heap内存下载到本地后,可以用MAT工具分析内存泄露,还有一些自带命令可以方便分析。
1)jmap:列出堆中的当前java对象
/opt/ibm/java/bin/jmap -histo xx > heap.log
2)jmap:导出heap
/opt/ibm/java/bin/jmap -dump:live,format=b,file=/home/temp/heap.log xx
3)jhat:java heap analyse tool,java堆的分析命令,可以将堆中的对象以html的形式显示出来,包括对象的数量,大小等等,
并支持对象查询语言
/opt/ibm/java/bin/jhat heap.log,启动命令堆内存不足时,指定堆大小 jhat -J-Xmx512m heap.log
查看分析后的html文档,http://localhost:7000
4)jstat:java statistics monitoring tool,主要利用JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括了对Heap size和垃圾回收状况的监控。
jstat [Options] vmid [interval] [count]
Options ,一般使用 -gcutil 查看gc情况 ;
vmid ,VM的进程号,即当前运行的java进程号;
interval: 间隔时间,单位为秒或者毫秒
count , 打印次数,如果缺省则打印无数次
4.1间隔1s查看gc情况
sudo -u admin /opt/ibm/java/bin/jstat -gcutil 4190 1s
S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 4.73 57.58 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 57.97 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 58.20 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 58.33 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 58.58 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 58.86 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 59.34 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 59.70 49.01 59.94 860 22.252 386 498.552 520.803 0.00 4.73 60.01 49.01 59.94 860 22.252 386 498.552 520.803
4.2异常gc,s0和s1完全无用,对象直接分配在eden区,导致young很快占满后马上full gc
S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 100.00 69.57 41.55 27 6.632 44 187.973 194.606 0.00 0.00 16.53 70.76 41.55 27 6.632 44 198.962 205.595 0.00 0.00 86.21 70.76 41.55 27 6.632 45 198.962 205.595 0.00 0.00 100.00 70.76 41.55 28 6.632 46 199.754 206.386minor gc太少了,很多临时对象没有被minor gc消灭掉,需要增大s0和s1,把参数-XX:SurvivorRatio=10改为-XX:SurvivorRatio=8,再重启后fullgc正常
8.30 0.00 43.32 77.38 52.67 115 9.467 4 8.228 17.694 8.30 0.00 52.69 77.38 52.67 115 9.467 4 8.228 17.694 8.30 0.00 58.75 77.38 52.67 115 9.467 4 8.228 17.694 8.30 0.00 63.94 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 69.63 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 73.61 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 80.52 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 85.72 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 92.19 77.38 52.68 115 9.467 4 8.228 17.694 8.30 0.00 97.30 77.38 52.68 115 9.467 4 8.228 17.694 0.00 7.11 6.25 77.42 52.68 116 9.485 4 8.228 17.713 0.00 7.11 10.95 77.42 52.68 116 9.485 4 8.228 17.713 0.00 7.11 16.00 77.42 52.68 116 9.485 4 8.228 17.713 0.00 7.11 20.17 77.42 52.68 116 9.485 4 8.228 17.713 0.00 7.11 27.25 77.42 52.68 116 9.485 4 8.228 17.713 0.00 7.11 32.05 77.42 52.68 116 9.485 4 8.228 17.713
4.3 经过调整后,还有1台机器有fullgc异常,如图
S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 0.00 40.67 76.86 44.57 49 7.997 188 468.193 476.190 0.00 0.00 40.71 76.86 44.57 49 7.997 188 468.193 476.190 0.00 0.00 40.77 76.86 44.57 49 7.997 189 468.514 476.511 0.00 0.00 40.83 76.86 44.57 49 7.997 189 468.514 476.511 0.00 0.00 40.85 76.86 44.57 49 7.997 190 468.514 476.511 0.00 0.00 40.88 76.86 44.57 49 7.997 190 468.812 476.809 0.00 0.00 41.02 76.86 44.57 49 7.997 190 468.812 476.809 0.00 0.00 41.08 76.86 44.57 49 7.997 190 468.812 476.809 0.00 0.00 41.11 76.86 44.57 49 7.997 190 468.812 476.809 0.00 0.00 41.17 76.86 44.57 49 7.997 190 468.812 476.809 0.00 0.00 41.20 76.86 44.57 49 7.997 191 469.142 477.138 0.00 0.00 41.25 76.86 44.57 49 7.997 192 469.447 477.444 0.00 0.00 41.38 76.86 44.58 49 7.997 192 469.447 477.444某牛人回复怀疑jvm自行触发了fullgc,把-XX:CMSInitiatingOccupancyFraction=80调整为-XX:+UseCMSInitiatingOccupancyOnly后gc正常了。