SNS 即时通讯项目性能优化

最近SNS项目会卡死,通过配置GC日志( -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC  -XX:+PrintGCApplicationStoppedTime  -Xloggc:logs/gc.log)

{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 149312K, used 128000K [0x00002aaad69b0000, 0x00002aaae1050000, 0x00002aaae1050000)
  eden space 128000K, 100% used [0x00002aaad69b0000,0x00002aaade6b0000,0x00002aaade6b0000)
  from space 21312K, 0% used [0x00002aaadfb80000,0x00002aaadfb80000,0x00002aaae1050000)
  to   space 21312K, 0% used [0x00002aaade6b0000,0x00002aaade6b0000,0x00002aaadfb80000)
 PSOldGen        total 341376K, used 0K [0x00002aaac1c50000, 0x00002aaad69b0000, 0x00002aaad69b0000)
  object space 341376K, 0% used [0x00002aaac1c50000,0x00002aaac1c50000,0x00002aaad69b0000)
 PSPermGen       total 262144K, used 15218K [0x00002aaab1c50000, 0x00002aaac1c50000, 0x00002aaac1c50000)
  object space 262144K, 5% used [0x00002aaab1c50000,0x00002aaab2b2cb90,0x00002aaac1c50000)
3.022: [GC [PSYoungGen: 128000K->6733K(149312K)] 128000K->6733K(490688K), 0.0117010 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 149312K, used 6733K [0x00002aaad69b0000, 0x00002aaae1050000, 0x00002aaae1050000)
  eden space 128000K, 0% used [0x00002aaad69b0000,0x00002aaad69b0000,0x00002aaade6b0000)
  from space 21312K, 31% used [0x00002aaade6b0000,0x00002aaaded437f0,0x00002aaadfb80000)
  to   space 21312K, 0% used [0x00002aaadfb80000,0x00002aaadfb80000,0x00002aaae1050000)
 PSOldGen        total 341376K, used 0K [0x00002aaac1c50000, 0x00002aaad69b0000, 0x00002aaad69b0000)
  object space 341376K, 0% used [0x00002aaac1c50000,0x00002aaac1c50000,0x00002aaad69b0000)
 PSPermGen       total 262144K, used 15218K [0x00002aaab1c50000, 0x00002aaac1c50000, 0x00002aaac1c50000)
  object space 262144K, 5% used [0x00002aaab1c50000,0x00002aaab2b2cb90,0x00002aaac1c50000)
}

Total time for which application threads were stopped: 0.0128490 seconds

查看快照文件,将程序中占用内存比较高的代码优化。

jmap -dump:format=b,file=snsdump_2_25.hprof 21567

由于我这个程序是即时通讯的,所以需要查看进程的线程堆栈:

jamp -heap 29268

实时查看堆栈GC情况:

[root@zfsoftApp2 bin]# jstat -gcnew 23461
 S0C    S1C    S0U    S1U   TT MTT  DSS      EC       EU     YGC     YGCT  
122624.0 131072.0    0.0 104821.1  6  15 122624.0 786432.0 725368.5      5    0.352

现在jvm使用情况:

{Heap before GC invocations=5 (full 0):
 PSYoungGen      total 917504K, used 882385K [0x00002aaad8e50000, 0x00002aab18e50000, 0x00002aab18e50000)
  eden space 786432K, 100% used [0x00002aaad8e50000,0x00002aab08e50000,0x00002aab08e50000)
  from space 131072K, 73% used [0x00002aab10e50000,0x00002aab16c04680,0x00002aab18e50000)
  to   space 131072K, 0% used [0x00002aab08e50000,0x00002aab08e50000,0x00002aab10e50000)
 PSOldGen        total 487424K, used 0K [0x00002aaabb250000, 0x00002aaad8e50000, 0x00002aaad8e50000)
  object space 487424K, 0% used [0x00002aaabb250000,0x00002aaabb250000,0x00002aaad8e50000)
 PSPermGen       total 153600K, used 69988K [0x00002aaab1c50000, 0x00002aaabb250000, 0x00002aaabb250000)
  object space 153600K, 45% used [0x00002aaab1c50000,0x00002aaab60a9050,0x00002aaabb250000)
52.148: [GC [PSYoungGen: 882385K->104821K(917504K)] 882385K->104821K(1404928K), 0.1022700 secs] [Times: user=0.26 sys=0.03, real=0.10 secs] 
Heap after GC invocations=5 (full 0):
 PSYoungGen      total 917504K, used 104821K [0x00002aaad8e50000, 0x00002aab18e50000, 0x00002aab18e50000)
  eden space 786432K, 0% used [0x00002aaad8e50000,0x00002aaad8e50000,0x00002aab08e50000)
  from space 131072K, 79% used [0x00002aab08e50000,0x00002aab0f4ad480,0x00002aab10e50000)
  to   space 122624K, 0% used [0x00002aab11690000,0x00002aab11690000,0x00002aab18e50000)
 PSOldGen        total 487424K, used 0K [0x00002aaabb250000, 0x00002aaad8e50000, 0x00002aaad8e50000)
  object space 487424K, 0% used [0x00002aaabb250000,0x00002aaabb250000,0x00002aaad8e50000)
 PSPermGen       total 153600K, used 69988K [0x00002aaab1c50000, 0x00002aaabb250000, 0x00002aaabb250000)
  object space 153600K, 45% used [0x00002aaab1c50000,0x00002aaab60a9050,0x00002aaabb250000)
}

你可能感兴趣的:(SNS 即时通讯项目性能优化)