JAVA基础:JVM监测&工具探究:
提到的JVM参数的设置需要根据应用的特性来进行设置,每个参数的设置都需要对JVM进行长时间的监测,并不断进行调整才能找到最佳设置方案。本文将介绍如果通过工具及Java api来监测JVM的运行状态,并详细介绍各工具的使用方法。
需要监测的数据:(内存使用情况 谁使用了内存 GC的状况)
内存使用情况--heap&PermGen
@ 表示通过jmap –heap pid 可以获取的值
# 表示通过jstat –gcutil pid 可以获取的值
参数的查看可以通过多种方法 本文中只随机列出一种。
描述 | 最大值 | 当前值 | 报警值 |
堆内存 | @Heap Configuration::MaxHeapSize sum(eden+servivor+old) |
sum(eden+servivor+old) | 自设 |
非堆内存 | sum(perm+native) | 无 | |
Eden | @Eden Space::capacity | @Eden Space::used | 无 |
Survivor0 | @From Space::capacity | @From Space::used | 无 |
Survivor1 | @To Space::capacity | @To Space::used | 无 |
New gen (注意区别于Xmn参数设置) |
@New Generation::capacity Eden + 1 Survivor Space |
@New Generation::used | 无 |
Old gen | @concurrent mark-sweep generation::capacity (CMS是对old区的gc,所以此处即表示old gen) |
@concurrent mark-sweep generation::capacity(CMS)::used | 自设 |
Perm Gen | @Perm Generation::capacity | @Perm Generation::used | 自设 |
内存使用情况--config
描述 | 配置值 |
MaxTenuringThreshold | jinfo -flag MaxTenuringThreshold pid |
MinHeapFreeRatio | @Heap Configuration::MinHeapFreeRatio |
MaxHeapFreeRatio | @Heap Configuration::MaxHeapFreeRatio |
new gen gc | @using … in the new generation |
old gen gc | new gen gc声明下方 |
类总数统计 | ?? |
内存使用情况—C heap
◆ top or ps aux
谁使用了内存
◆ Heap
jmap –histo
jmap –dump ,then mat
◆ C heap
google perftools
GC的状况
描述 | 收集次数 | 收集时间 | 应用暂停时间 |
Full GC | #FGC | #FGCT | 设置-XX:+PrintGCApplicationStoppedTime后在日志中查看 |
Young GC | #YGC | #YGCT | 同上 |
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log
常用工具介绍:jinfo jmap jstack jstat
◆ 可以从一个给定的java进程或core文件或远程debug服务器上获取java配置信息。包括java系统属性及JVM参数(command line flags)。注意在jvm启动参数中没有配置的参数也可使用jinfo –flag xxx pid输出默认值(很有用,但貌似一些简写的参数查不出来)。
◆ 可以修改运行时的java 进程的opts。
◆ 只有solaris和linux的JDK版本里有。
◆ 使用方式可使用jinfo –h 查询。
观察运行中的jvm物理内存的占用情况。
如果连用SHELL jmap -histo pid>a.log可以将其保存到文本中去,在一段时间后,使用文本对比工具,可以对比出GC回收了哪些对象。
参数很简单,直接查看jmap -h
举例:
- jmap -heap pid
- jmap -dump:format=b,file=heap.hprof <pid>
dump文件可以通过MemoryAnalyzer分析查看.网址:http://www.eclipse.org/mat/,可以查看dump时对象数量,内存占用,线程情况等。
观察jvm中当前所有线程的运行情况和线程当前状态
如果java程序崩溃生成core文件,jstack工具可以用来获得core文件的java stack和native stack的信息,从而可以轻松地知道java程序是如何崩溃和在程序何处发生问题。另外,jstack工具还可以附属到正在运行的java程序中,看到当时运行的java程序的java stack和native stack的信息, 如果现在运行的java程序呈现hung的状态,jstack是非常有用的。目前只有在Solaris和Linux的JDK版本里面才有。
参数很简单,直接查看jstack -h
举例:
- jstack pid
JVM监测工具(Java Virtual Machine Statistics Monitoring Tool)。利用了JVM内建的指令对Java应用程序的资源和性能进行实时的命令行的监控,包括各种堆和非堆的大小及其内存使用量、classloader、compiler、垃圾回收状况等。
举例:
- jstat –printcompilation -h10 3024 250 600
每250毫秒打印一次,一共打印600次 每隔10行显示一次head
语法结构:
- Usage: jstat -help|-options
- jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
参数介绍:
◆ -h n 每隔几行输出标题
◆ vmid VM的进程号,即当前运行的java进程号
◆ -t 在第一列显示自JVM启动以来的时间戳
◆ -J 修改java进程的参数。类似jinfo -flag <name>=<value>。例如-J-Xms48m 设置初始堆为48M。详见这里。这个参数挺有用的,可以在运行中调整参数以方便测试、监测。
◆ -option option为要检测的参数。参数列表可通过jstat –options 获取。下面将分别介绍每个参数及输出字段的含义。
class | 统计class loader行为信息 |
compiler | 统计编译行为信息 |
gc | 统计jdk gc时heap信息 |
gccapacity | 统计堆内存不同代的heap容量信息 |
gccause | 统计gc的情况(同-gcutil)和引起gc的事件 |
gcnew | 统计gc时新生代的信息(相比gcutil更详细) |
gcnewcapacity | 统计gc时新生代heap容量 |
gcold | 统计gc时,老年区的情况 |
gcoldcapacity | 统计gc时,老年区heap容量 |
gcpermcapacity | 统计gc时,permanent区heap容量 |
gcutil | 统计gc时,heap情况 |
printcompilation | 统计编译行为信息 |
-class option:Class Loader Statistics
Loaded | Number of classes loaded. |
Bytes | Number of Kbytes loaded. |
Unloaded | Number of classes unloaded. |
Bytes | Number of Kbytes unloaded. |
Time | Time spent performing class load and unload operations. |
-compiler:HotSpot Just-In-Time Compiler Statistics
Compiled | Number of compilation tasks performed. |
Failed | Number of compilation tasks that failed. |
Invalid | Number of compilation tasks that were invalidated. |
Time | Time spent performing compilation tasks. |
FailedType | Compile type of the last failed compilation. |
FailedMethod | Class name and method for the last failed compilation. |
-gc Option:Garbage-collected heap statistics
S0C | Current survivor space 0 capacity (KB). |
S1C | Current survivor space 1 capacity (KB). |
S0U | Survivor space 0 utilization (KB). |
S1U | Survivor space 1 utilization (KB). |
EC | Current eden space capacity (KB). |
EU | Eden space utilization (KB). |
OC | Current old space capacity (KB). |
OU | Old space utilization (KB). |
PC | Current permanent space capacity (KB). |
PU | Permanent space utilization (KB). |
YGC | Number of young generation GC Events. |
YGCT | Young generation garbage collection time. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
-gccapacity Option:Memory Pool Generation and Space Capacities
NGCMN | Minimum new generation capacity (KB). |
NGCMX | Maximum new generation capacity (KB). |
NGC | Current new generation capacity (KB). |
S0C | Current survivor space 0 capacity (KB). |
S1C | Current survivor space 1 capacity (KB). |
EC | Current eden space capacity (KB). |
OGCMN | Minimum old generation capacity (KB). |
OGCMX | Maximum old generation capacity (KB). |
OGC | Current old generation capacity (KB). |
OC | Current old space capacity (KB). |
PGCMN | Minimum permanent generation capacity (KB). |
PGCMX | Maximum Permanent generation capacity (KB). |
PGC | Current Permanent generation capacity (KB). |
PC | Current Permanent space capacity (KB). |
YGC | Number of Young generation GC Events. |
FGC | Number of Full GC Events. |
-gccause Option:Garbage Collection Statistics, Including GC Events
LGCC | Cause of last Garbage Collection. |
GCC | Cause of current Garbage Collection. |
前面的字段与gcutil相同.
-gcnew Option:New Generation Statistics
S0C | Current survivor space 0 capacity (KB). |
S1C | Current survivor space 1 capacity (KB). |
S0U | Survivor space 0 utilization (KB). |
S1U | Survivor space 1 utilization (KB). |
TT | Tenuring threshold. |
MTT | Maximum tenuring threshold. |
DSS | Desired survivor size (KB). |
EC | Current eden space capacity (KB). |
EU | Eden space utilization (KB). |
YGC | Number of young generation GC events. |
YGCT | Young generation garbage collection time. |
-gcnewcapacity Option:New Generation Space Size Statistics
NGCMN |
Minimum new generation capacity (KB). |
NGCMX | Maximum new generation capacity (KB). |
NGC | Current new generation capacity (KB). |
S0CMX | Maximum survivor space 0 capacity (KB). |
S0C | Current survivor space 0 capacity (KB). |
S1CMX | Maximum survivor space 1 capacity (KB). |
S1C | Current survivor space 1 capacity (KB). |
ECMX | Maximum eden space capacity (KB). |
EC | Current eden space capacity (KB). |
YGC | Number of young generation GC events. |
FGC | Number of Full GC Events. |
-gcold Option:Old and Permanent Generation Statistics
PC | Current permanent space capacity (KB). |
PU | Permanent space utilization (KB). |
OC | Current old space capacity (KB). |
OU | old space utilization (KB). |
YGC | Number of young generation GC events. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
-gcoldcapacity Option:Old Generation Statistics
OGCMN | Minimum old generation capacity (KB). |
OGCMX | Maximum old generation capacity (KB). |
OGC | Current old generation capacity (KB). |
OC | Current old space capacity (KB). |
YGC | Number of young generation GC events. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
-gcpermcapacity Option: Permanent Generation Statistics
PGCMN | Minimum permanent generation capacity (KB). |
PGCMX | Maximum permanent generation capacity (KB). |
PGC | Current permanent generation capacity (KB). |
PC | Current permanent space capacity (KB). |
YGC | Number of young generation GC events. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
-gcutil Option:Summary of Garbage Collection Statistics
S0 | Survivor space 0 utilization as a percentage of the space's current capacity. |
S1 | Survivor space 1 utilization as a percentage of the space's current capacity. |
E | Eden space utilization as a percentage of the space's current capacity. |
O | Old space utilization as a percentage of the space's current capacity. |
P | Permanent space utilization as a percentage of the space's current capacity. |
YGC | Number of young generation GC events. |
YGCT | Young generation garbage collection time. |
FGC | Number of full GC events. |
FGCT | Full garbage collection time. |
GCT | Total garbage collection time. |
-printcompilation Option: HotSpot Compiler Method Statistics
Compiled | Number of compilation tasks performed. |
Size | Number of bytes of bytecode for the method. |
Type | Compilation type. |
Method | Class name and method name identifying the compiled method. Class name uses "/" instead of "." as namespace separator. Method name is the method within the given class. The format for these two fields is consistent with the HotSpot - XX:+PrintComplation option. |
相关推荐
调用JVM自带的监测软件,主要显示运行状态下JVM内存的使用,网络状况等。
1.怎么运行?编译装载执行机制 2.怎么配置?JVM内存分代 3.怎么配置?GC垃圾回收 4.怎么监测?JVM监测工具 5.怎么监测?Linux监测工具 6.怎么调优?内存调优
1.jps 2.jstack 3.jstat 4.jmap 5.jinfo 6.jcmd 7.jhat
我想你肯定遇到过内存溢出,或是内存使用率过高的问题。碰到内存持续上升的情况,其实我们很难从业务日志中查看到具体的问题,那么面对多个进程以及大量业务线程,我们该如何精准地找到背后的原因呢?
最常用到的就是对于 JVM 的监测和管理,比如 JVM 内存、CPU 使用率、线程数、垃圾收集情况等等。另外,还可以用作日志级别的动态修改,比如 log4j 就支持 JMX 方式动态修改线上服务的日志级别。最主要的还是被用来做...
JavaMelody 能够监测Java或Java EE应用程序服务器,并以图表的方式显示:Java内存和Java CPU使用情况,用户Session数量,JDBC连接数,和http请求、sql请求、jsp页面与业务接口方法(EJB3、Spring、 Guice)的执行...
主要介绍了Jvm调优和SpringBoot项目优化,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
模块四,JVM 性能监测及调优。 模块五,设计模式调优。 模块六,数据库性能调优。 模块七,实战演练场。 性能优化手册是一套java性能学习研究小技巧,包含内容:Java性能优化、JVM性能优化、服务器性能优化、数据库...
VisualVM入门指南 使用说明 新手上路 JVM JAVA虚拟机 调试监测
此文档展现了JVM最新研究成果,主要是关于动态监测JVM的资源分配。对于JVM的研究人员具有参考价值。
JProfiler使用说明 如何分析 分析案例 JAVA虚拟机性能监测调优,比jconsole,jvirtualVM,jmap好多用了,不会死机,能轻松调试大型java程序,是Jprofiler全书的中文版,值得收藏下载。
功能包括内存分析、快照功能、转储功能、CPU分析等等,系统管理员可以利用它来监测、控制Java应用程序横跨整个网络的情况。 它集成了多个JDK命令工具的一个可视化工具,它主要用来监控JVM的运行情况,
Arthas 是一款线上监控诊断产品,通过全局视角实时查看应用 load、内存、gc、线程的状态信息,并能在不修改应用代码的情况下,对业务问题进行诊断,包括查看方法调用的出入参、异常,监测方法执行耗时,类加载信息等...
适用场景:服务器均可适用,主要是监测服务器的使用状态。 使用方法: 1.添加工程依赖 <!-- 获取系统信息 --> <groupId>com.github.oshi</groupId> <artifactId>oshi-core <version>5.8.2 2. 把工具放进去 3...
使用 Instrumentation,开发者可以构建一个独立于应用程序的代理程序(Agent),用来监测和协助运行在 JVM 上的程序,甚至能够替换和修改某些类的定义。有了这样的功能,开发者就可以实现更为灵活的运行时虚拟机监控...
使用 Instrumentation,开发者可以构建一个独立于应用程序的代理程序(Agent),用来监测和协助运行在 JVM 上的程序,甚至能够替换和修改某些类的定义。有了这样的功能,开发者就可以实现更为灵活的运行时虚拟机监控...
Java实现服务器监控相关代码,使用Maven引入了系统服务jar包. 包含:CPU相关信息、內存相关信息、JVM相关信息、服务器相关信息、磁盘相关信息。 CPU相关信息:核心数 CPU总的使用率 CPU系统使用率 CPU用户使用率等
例如,如果程序循环遍历数组中的所有元素,JVM 就可以优化数组的边界检查,使循环更快,展开循环能提供额外的加速。但如果循环是为了找到特定元素,那目前还没有什么优化的办法,使得遍历数组和采用HashMap 的版本...
Java Service Wrapper可为应用程序提供以下功能: (1)把应用安装为Windows服务或Linux守护进程;...(2)监测JVM运行情况,对于程序原因或内存溢出导致的虚拟机崩溃实现自动重启; (3)记录运行日志;
基于全球化架构的一站式体验监测平台实战 基于客诉体系的智能监控技术及系统实践 基于教练模式的研发效能改进实践 基于高频动态化场景的移动测试解决方案 基于JVM-Sandbox的一站式服务端稳定性方案 基于Jacoco的代码...