针对 Java 应用,性能诊断工具主要分为两层:OS 层面Java 应用层面(包括应用代码诊断和 GC 诊断);

1. OS诊断(关注CPU、内存和IO三方面):

  • Load Average top命令

    • 按照经验,若数值小于 0.7*CPU 个数,则系统工作正常;若超过这个值,甚至达到 CPU 核数的四五倍,则系统的负载就明显偏高;
      • CPU 使用率 top命令
      • 上下文切换次数(Context Switch) vmstat
      • 内存 free -m
      • IO(磁盘 iostat / 网络 )
        image

2. Java应用:

  • jstack + top -Hp pid (看运行时间较长的java线程)

  • GC诊断 jstat jmap

    printf "%x\n" 21488 ==> 53f0
    
    [xdpp@cdh6-slave4 ~]$ jstack -l 53f0
    Attaching to remote server 53f0, please wait...
    Error attaching to remote server: java.rmi.UnknownHostException: Unknown host: 53f0; nested exception is:
    	java.net.UnknownHostException: 53f0
    sun.jvm.hotspot.debugger.DebuggerException: java.rmi.UnknownHostException: Unknown host: 53f0; nested exception is:
    	java.net.UnknownHostException: 53f0
    	at sun.jvm.hotspot.RMIHelper.lookup(RMIHelper.java:115)
    	at sun.jvm.hotspot.HotSpotAgent.connectRemoteDebugger(HotSpotAgent.java:517)
    	at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:374)
    	at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
    	at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:183)
    	at sun.jvm.hotspot.tools.Tool.start(Tool.java:196
    
    jstat –gcxxx -t pid    # 打印 GC 详细信息
    [xd@cdh6-slave4 ~]$ jstat -gcutil -t 21488 4000
    Timestamp         S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT   
          1125664.7   0.00   3.82  29.87   0.00  94.03  91.20      3    0.265     2    0.204    0.469
          1125668.7   0.00   3.82  29.87   0.00  94.03  91.20      3    0.265     2    0.204    0.469
          1125672.7   0.00   3.82  29.87   0.00  94.03  91.20      3    0.265     2    0.204    0.469
          1125676.8   0.00   3.82  29.87   0.00  94.03  91.20      3    0.265     2    0.204    0.469
          1125680.8   0.00   3.82  29.87   0.00  94.03  91.20      3    0.265     2    0.204    0.469
    
    jmap –heap pid         # 打印 Java 进程堆信息
    
posted on 2023-04-12 23:38  anyu967  阅读(167)  评论(0编辑  收藏  举报