微服务轮子项目(50) -JVM 分析工具详解(上)

简介: 微服务轮子项目(50) -JVM 分析工具详解

1. JPS

JVM Process Status Tool,显示指定系统内所有的HotSpot虚拟机进程。

1.1 命令格式

jps [options] [hostid]

其中[option]、[hostid]参数也可以不写

1.2. option参数

  • l : 输出主类全名或jar路径
  • q : 只输出LVMID
  • m : 输出JVM启动时传递给main()的参数
  • v : 输出JVM启动时显示指定的JVM参数

1.3 示例

$jps -l
15336 com.jvm.jconsole.ThreadConsole
19816 org.jetbrains.jps.cmdline.Launcher
9704 jdk.jcmd/sun.tools.jps.Jps

2. jstat

jstat(JVM statistics Monitoring)是用于监视虚拟机运行时状态信息的命令,它可以显示出虚拟机进程中的类装载、内存、垃圾收集、JIT编译(Just In Time Compiler, 即时编译器)等运行数据。

2.1. 命令格式

jstat 

2.2 option参数

  • [option] : 操作参数
  • LVMID : 本地虚拟机进程ID
  • [interval] : 连续输出的时间间隔
  • [count] : 连续输出的次数

2.3. option 参数总览

Option Displays
class class loader的行为统计。Statistics on the behavior of the class loader.
compiler HotSpt JIT编译器行为统计。Statistics of the behavior of the HotSpot Just-in-Time compiler.
gc 垃圾回收堆的行为统计。Statistics of the behavior of the garbage collected heap.
gccapacity 各个垃圾回收代容量(young,old,perm)和他们相应的空间统计。Statistics of the capacities of the generations and their corresponding spaces.
gcutil 垃圾回收统计概述。Summary of garbage collection statistics.
gccause 垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因。Summary of garbage collection statistics (same as -gcutil), with the cause of the last and
gcnew 新生代行为统计。Statistics of the behavior of the new generation.
gcnewcapacity 新生代与其相应的内存空间的统计。Statistics of the sizes of the new generations and its corresponding spaces.
gcold 年老代和永生代行为统计。Statistics of the behavior of the old and permanent generations.
gcoldcapacity 年老代行为统计。Statistics of the sizes of the old generation.
gcpermcapacity 永生代行为统计。Statistics of the sizes of the permanent generation.
printcompilation HotSpot编译方法统计。HotSpot compilation method statistics.

2.4 option 参数详解

2.4.1 -class
  • 监视类装载、卸载数量、总空间以及耗费的时间
$ jstat -class 11589
 Loaded  Bytes  Unloaded  Bytes     Time   
  7035  14506.3     0     0.0       3.67
  • Loaded : 加载class的数量
  • Bytes : class字节大小
  • Unloaded : 未加载class的数量
  • Bytes : 未加载class的字节大小
  • Time : 加载时间
2.4.2 -compiler
  • 输出JIT编译过的方法数量耗时等
$ jstat -compiler 1262
Compiled Failed Invalid   Time   FailedType FailedMethod
    2573      1       0    47.60          1 org/apache/catalina/loader/WebappClassLoader findResourceInternal
  • Compiled : 编译数量
  • Failed : 编译失败数量
  • Invalid : 无效数量
  • Time : 编译耗时
  • FailedType : 失败类型
  • FailedMethod : 失败方法的全限定名
2.4.3 -gc
  • 垃圾回收堆的行为统计,常用命令
$ jstat -gc 1262
 S0C    S1C     S0U     S1U   EC       EU        OC         OU        PC       PU         YGC    YGCT    FGC    FGCT     GCT   
26112.0 24064.0 6562.5  0.0   564224.0 76274.5   434176.0   388518.3  524288.0 42724.7    320    6.417   1      0.398    6.815

C即Capacity 总容量,U即Used 已使用的容量

S0C : survivor0区的总容量

S1C : survivor1区的总容量

S0U : survivor0区已使用的容量

S1U : survivor1区已使用的容量

EC : Eden区的总容量

EU : Eden区已使用的容量

OC : Old区的总容量

OU : Old区已使用的容量 PC 当前perm的容量 (KB) PU perm的使用 (KB)

YGC : 新生代垃圾回收次数

YGCT :新生代垃圾回收时间

FGC : 老年代垃圾回收次数

FGCT : 老年代垃圾回收时间

GCT : 垃圾回收总消耗时间

$ jstat -gc 1262  2000  20

这个命令意思就是每隔2000ms输出1262的gc情况,一共输出20次

2.4.4 -gccapacity
  • 同-gc,不过还会输出Java堆各区域使用到的最大、最小空间
$ jstat -gccapacity 1262
 NGCMN    NGCMX     NGC    S0C   S1C       EC         OGCMN      OGCMX      OGC        OC       PGCMN    PGCMX     PGC      PC         YGC    FGC 
614400.0 614400.0 614400.0 26112.0 24064.0 564224.0   434176.0   434176.0   434176.0   434176.0 524288.0 1048576.0 524288.0 524288.0    320     1  
  • NGCMN : 新生代占用的最小空间
  • NGCMX : 新生代占用的最大空间
  • OGCMN : 老年代占用的最小空间
  • OGCMX : 老年代占用的最大空间
  • OGC:当前年老代的容量 (KB)
  • OC:当前年老代的空间 (KB)
  • PGCMN : perm占用的最小空间
  • PGCMX : perm占用的最大空间
2.4.5 -gcutil

同-gc,不过输出的是已使用空间占总空间的百分比

$ jstat -gcutil 28920
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT   
 12.45   0.00  33.85   0.00   4.44  4       0.242     0    0.000    0.242
2.4.6 -gccause

垃圾收集统计概述(同-gcutil),附加最近两次垃圾回收事件的原因

$ jstat -gccause 28920
  S0     S1     E      O      P       YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC                 
 12.45   0.00  33.85   0.00   4.44      4    0.242     0    0.000    0.242   Allocation Failure   No GC  
  • LGCC:最近垃圾回收的原因
  • GCC:当前垃圾回收的原因
2.4.7 -gcnew

统计新生代的行为

$ jstat -gcnew 28920
 S0C      S1C      S0U        S1U  TT  MTT  DSS      EC        EU         YGC     YGCT  
 419392.0 419392.0 52231.8    0.0  6   6    209696.0 3355520.0 1172246.0  4       0.242
  • TT:Tenuring threshold(提升阈值)
  • MTT:最大的tenuring threshold
  • DSS:survivor区域大小 (KB)
2.4.8 -gcnewcapacity

新生代与其相应的内存空间的统计

$ jstat -gcnewcapacity 28920
  NGCMN      NGCMX       NGC      S0CMX     S0C     S1CMX     S1C       ECMX        EC        YGC   FGC 
 4194304.0  4194304.0  4194304.0 419392.0 419392.0 419392.0 419392.0  3355520.0  3355520.0     4     0
  • NGC:当前年轻代的容量 (KB)
  • S0CMX:最大的S0空间 (KB)
  • S0C:当前S0空间 (KB)
  • ECMX:最大eden空间 (KB)
  • EC:当前eden空间 (KB)


目录
相关文章
|
9天前
|
缓存 Java
《JVM由浅入深学习九】 2024-01-15》JVM由简入深学习提升分(生产项目内存飙升分析)
《JVM由浅入深学习九】 2024-01-15》JVM由简入深学习提升分(生产项目内存飙升分析)
12 0
|
2月前
|
微服务
jeecg微服务项目调用接口报错Token验证失效的解决方法
jeecg微服务项目调用接口报错Token验证失效的解决方法
|
4天前
|
消息中间件 负载均衡 Java
最容易学会的springboot gralde spring cloud 多模块微服务项目
最容易学会的springboot gralde spring cloud 多模块微服务项目
|
2月前
|
SpringCloudAlibaba Java 持续交付
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
321 0
|
2天前
|
Java 微服务 Spring
微服务04---服务远程调用,根据订单id查询订单功能,根据id查询订单的同时,把订单所属的用户信息一起返回,Spring提供了一个工具RestTemplate,Bean写在对象前面,以后可以在任何地
微服务04---服务远程调用,根据订单id查询订单功能,根据id查询订单的同时,把订单所属的用户信息一起返回,Spring提供了一个工具RestTemplate,Bean写在对象前面,以后可以在任何地
|
2月前
|
监控 数据可视化 安全
智慧工地SaaS可视化平台源码,PC端+APP端,支持二开,项目使用,微服务+Java++vue+mysql
环境实时数据、动态监测报警,实时监控施工环境状态,有针对性地预防施工过程中的环境污染问题,打造文明生态施工,创造绿色的生态环境。
32 0
智慧工地SaaS可视化平台源码,PC端+APP端,支持二开,项目使用,微服务+Java++vue+mysql
|
2月前
|
Java Maven 微服务
微服务项目-将普通文件夹设为模块与添加services窗口
微服务项目-将普通文件夹设为模块与添加services窗口
16 0
|
2月前
|
Arthas 监控 Java
金石原创 |【JVM实战系列】「监控调优体系」实战开发arthas-spring-boot-starter监控你的微服务是否健康!
金石原创 |【JVM实战系列】「监控调优体系」实战开发arthas-spring-boot-starter监控你的微服务是否健康!
38 0
|
2月前
|
Cloud Native Dubbo Java
如何确定微服务项目中Spring Boot、Spring Cloud、Spring Cloud Alibaba三者之间的版本
如何确定微服务项目中Spring Boot、Spring Cloud、Spring Cloud Alibaba三者之间的版本
71 0
|
2月前
|
XML Java 数据格式
springboot 微服务项目如何集成 html 页面
springboot 微服务项目如何集成 html 页面
48 0