JVM 性能调优监控工具 jps jstat jinfo jmap jhat jstack

用户头像
wkq2786130
关注
发布于: 2020 年 07 月 22 日



原文 http://weikeqin.com/2020/03/28/jvm-performance-tuning-monitoring-tool/



最近测试环境总是莫名的出问题,然后部署服务的容器里除了服务打印的日志,没有其它信息,想看看是什么原因导致服务很卡,是不是有哪块代码占用内存高。

代码执行缓慢、OutOfMemoryError,内存不足、内存泄露、线程死锁、锁争用(Lock Contention)、Java进程消耗CPU过高 都可以使用JDK的命令行工具排查。



<br>



(1) JDK的命令行工具



jps、jstat、jinfo、jmap、jhat、jstack、hprof

jps : 虚拟机进程状况工具

jstat : 虚拟机统计信息监视工具

jinfo : Java 配置信息工具

jmap : Java 内存映像工具

jhat : 虚拟机堆转储快照分析工具

jstack : Java 堆栈跟踪工具



jps将打印所有正在运行的 Java 进程。

jstat允许用户查看目标 Java 进程的类加载、即时编译以及垃圾回收相关的信息。它常用于检测垃圾回收问题以及内存泄漏问题。

jmap允许用户统计目标 Java 进程的堆中存放的 Java 对象,并将它们导出成二进制文件。

jinfo将打印目标 Java 进程的配置参数,并能够改动其中 manageabe 的参数。

jstack将打印目标 Java 进程中各个线程的栈轨迹、线程状态、锁状况等信息。它还将自动检测死锁。

jcmd则是一把瑞士军刀,可以用来实现前面除了jstat之外所有命令的功能。



Java虚拟机的监控及诊断工具-GUI



JConsole : Java 监视与管理控制台

VisualVM : 多合一故障处理工具

eclipse MAT

JMC

JITWatch



<br>



(2) 虚拟机进程状况工具 jps (JVM Process Status Tool)



jps主要用来输出JVM中运行的进程状态信息。

jps命令使用Java启动器来查找传递给main方法的类名和参数。



[wkq@VM_77_25_centos ~]$ jps -help
usage: jps [-help]
jps [-q] [-mlvV] [<hostid>]
Definitions:
<hostid>: <hostname>[:<port>]
[wkq@VM_77_25_centos ~]$



(2.1) jps命令



jps命令用于输出JVM中运行的进程状态信息。可以获取到进程的pid、全限定名、传入main方法的参数、传入JVM的参数 等。



语法格式

jps [ options ] [ hostid ]



如果不指定hostid就默认为当前主机或服务器。



详细信息见 man jps



(2.1.1) jps 不加参数



在本地主机上搜索检测到的JVM。



[wkq@VM_77_25_centos ~]$ jps
14916 Jps
13050 Elasticsearch
[wkq@VM_77_25_centos ~]$
[wkq@VM_77_25_centos ~]$



<!--more-->



(2.1.2) jps -q

不输出类名、Jar名和传入main方法的参数



[wkq@VM_77_25_centos ~]$ jps -q
15059
13050
[wkq@VM_77_25_centos ~]$



(2.1.3) jps -m



显示传递给main方法的参数。对于嵌入式JVM,输出可能为null。



[wkq@VM_77_25_centos ~]$ jps -m
15092 Jps -m
13050 Elasticsearch -d
[wkq@VM_77_25_centos ~]$



(2.1.4) jps -l



输出main类或Jar的全限定名



[wkq@VM_77_25_centos ~]$ jps -l
15139 sun.tools.jps.Jps
13050 org.elasticsearch.bootstrap.Elasticsearch
[wkq@VM_77_25_centos ~]$



(2.1.5) jps -v



显示传递给JVM的参数。



[wkq@VM_77_25_centos ~]$ jps -v
15157 Jps -Denv.class.path=.:/home/wkq/software/jdk1.8.0_172/lib/dt.jar:/home/wkq/software/jdk1.8.0_172/lib/tools.jar -Dapplication.home=/home/wkq/software/jdk1.8.0_172 -Xms8m
13050 Elasticsearch -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-5035355569386013893 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/wkq/software/elasticsearch-6.6.2 -Des.path.conf=/home/wkq/software/elasticsearch-6.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar
[wkq@VM_77_25_centos ~]$



(2.1.6) jps -V



禁止输出类名,JAR全限定名和传递给main方法的参数的输出,从而产生仅本地JVM标识符的列表。



[wkq@VM_77_25_centos ~]$ jps -V
15204 Jps
13050 Elasticsearch
[wkq@VM_77_25_centos ~]$



(2.2) 常用jps命令



(2.2.1) jps -lm



显示 pid、全限定名、传递给main方法的参数



[wkq@VM_77_25_centos ~]$ jps -lm
17539 sun.tools.jps.Jps -lm
13050 org.elasticsearch.bootstrap.Elasticsearch -d
[wkq@VM_77_25_centos ~]$
[wkq@VM_77_25_centos ~]$



(2.2.2) jps -lvm



显示 pid、全限定名、传递给main方法的参数、传递给JVM的参数



[wkq@VM_77_25_centos ~]$ jps -lvm
13050 org.elasticsearch.bootstrap.Elasticsearch -d -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-5035355569386013893 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/wkq/software/elasticsearch-6.6.2 -Des.path.conf=/home/wkq/software/elasticsearch-6.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar
17567 sun.tools.jps.Jps -lvm -Denv.class.path=.:/home/wkq/software/jdk1.8.0_172/lib/dt.jar:/home/wkq/software/jdk1.8.0_172/lib/tools.jar -Dapplication.home=/home/wkq/software/jdk1.8.0_172 -Xms8m
[wkq@VM_77_25_centos ~]$



<br>



(3) 虚拟机统计信息监视工具 jstat (JVM Statics Monitoring Tool)

jstat是用于监视虚拟机各种运行状态信息的命令行工具。



(3.1) jstat命令



语法格式

jstat [ generalOption | outputOptions vmid [ interval[s|ms] [ count ] ]



详细信息见 man jstat



(3.1.1) jstat命令



[wkq@VM_77_25_centos ~]$ jstat -help
Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
[wkq@VM_77_25_centos ~]$



[wkq@VM_77_25_centos ~]$ jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
[wkq@VM_77_25_centos ~]$



<br>



(3.1.1) jstat -class 13050



[wkq@VM_77_25_centos ~]$ jstat -class 13050
Loaded Bytes Unloaded Bytes Time
15177 27005.8 41 49.7 24.44
[wkq@VM_77_25_centos ~]$



(3.1.2) jstat -compiler 13050

[wkq@VM_77_25_centos ~]$ jstat -compiler 13050
Compiled Failed Invalid Time FailedType FailedMethod
7469 0 0 43.18 0
[wkq@VM_77_25_centos ~]$



(3.1.3) jstat -gc 13050

[wkq@VM_77_25_centos ~]$ jstat -gc 13050
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
8512.0 8512.0 0.0 24.5 68160.0 6380.0 963392.0 61694.4 77732.0 71385.7 11984.0 9862.8 69 2.112 6 0.286 2.397
[wkq@VM_77_25_centos ~]$



| 参数 | 描述 | 原文 |

|------|---------------------------------------|--------------------------------------------------------|

| S0C | 年轻代中第一个survivor 的容量 \(kB\) | Current survivor space 0 capacity \(kB\)\. |

| S1C | 年轻代中第二个survivor 的容量 \(kB\) | Current survivor space 1 capacity \(kB\)\. |

| S0U | 年轻代中第一个survivor 已使用空间 \(kB\) | Survivor space 0 utilization \(kB\)\. |

| S1U | 年轻代中第二个survivor已使用空间 \(kB\) | Survivor space 1 utilization \(kB\)\. |

| EC | 年轻代中 Eden space 的容量 \(kB\) | Current eden space capacity \(kB\)\. |

| EU | 年轻代中Eden space 目前已使用空间 \(kB\) | Eden space utilization \(kB\)\. |

| OC | Old space的容量 \(kB\) | Current old space capacity \(kB\)\. |

| OU | Old space 已使用空间 \(kB\) | Old space utilization \(kB\)\. |

| MC | Metaspace 的容量 \(kB\) | Metaspace capacity \(kB\)\. |

| MU | Metaspace 已使用空间 \(kB\) | Metacspace utilization \(kB\)\. |

| CCSC | Compressed class spcage 容量 \(kB\) | Compressed class space capacity \(kB\)\. |

| CCSU | Compressed class spcage 已使用空间 \(kB\) | Compressed class space used \(kB\)\. |

| YGC | 从应用程序启动到采样时年轻代中gc次数 | Number of young generation garbage collection events\. |

| YGCT | 从应用程序启动到采样时年轻代中gc所用时间 \(s\) | Young generation garbage collection time\. |

| FGC | 从应用程序启动到采样时old代 \(全gc\) gc次数 | Number of full GC events\. |

| FGCT | 从应用程序启动到采样时old代 \(全gc\) gc所用时间 \(s\) | Full garbage collection time\. |

| GCT | 从应用程序启动到采样时gc用的总时间 \(s\) | Total garbage collection time\. |



(3.1.4) jstat -gccapacity 13050

[wkq@VM_77_25_centos ~]$ jstat -gccapacity 13050
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
85184.0 85184.0 85184.0 8512.0 8512.0 68160.0 963392.0 963392.0 963392.0 963392.0 0.0 1116160.0 77732.0 0.0 1048576.0 11984.0 69 6
[wkq@VM_77_25_centos ~]$



(3.1.5) jstat -gccause 13050

[wkq@VM_77_25_centos ~]$ jstat -gccause 13050
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT LGCC GCC
0.00 0.29 11.90 6.40 91.84 82.30 69 2.112 6 0.286 2.397 Allocation Failure No GC
[wkq@VM_77_25_centos ~]$



(3.1.6) jstat -gcmetacapacity 13050

[wkq@VM_77_25_centos ~]$ jstat -gcmetacapacity 13050
MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC FGCT GCT
0.0 1116160.0 77732.0 0.0 1048576.0 11984.0 69 6 0.286 2.397
[wkq@VM_77_25_centos ~]$



(3.1.7) jstat -gcnew 13050

[wkq@VM_77_25_centos ~]$ jstat -gcnew 13050
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
8512.0 8512.0 0.0 24.5 6 6 4256.0 68160.0 13229.3 69 2.112
[wkq@VM_77_25_centos ~]$



(3.1.8) jstat -gcnewcapacity 13050

[wkq@VM_77_25_centos ~]$ jstat -gcnewcapacity 13050
NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC
85184.0 85184.0 85184.0 8512.0 8512.0 8512.0 8512.0 68160.0 68160.0 69 6
[wkq@VM_77_25_centos ~]$



(3.1.9) jstat -gcold 13050

[wkq@VM_77_25_centos ~]$ jstat -gcold 13050
MC MU CCSC CCSU OC OU YGC FGC FGCT GCT
77732.0 71385.7 11984.0 9862.8 963392.0 61694.4 69 6 0.286 2.397



(3.1.10) jstat -gcoldcapacity 13050

[wkq@VM_77_25_centos ~]$ jstat -gcoldcapacity 13050
OGCMN OGCMX OGC OC YGC FGC FGCT GCT
963392.0 963392.0 963392.0 963392.0 69 6 0.286 2.397
[wkq@VM_77_25_centos ~]$



(3.1.11) jstat -gcutil 13050



垃圾回收状态摘要



[wkq@VM_77_25_centos ~]$ jstat -gcutil 13050
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.29 24.37 6.40 91.84 82.30 69 2.112 6 0.286 2.397
[wkq@VM_77_25_centos ~]$



| 参数 | 描述 | 原文 |

|------|-----------------------------------|--------------------------------------------------------------------------------|

| S0 | 年轻代中第一个survivor 已使用的占当前容量百分比 | Survivor space 0 utilization as a percentage of the space's current capacity\. |

| S1 | 年轻代中第二个survivor 已使用的占当前容量百分比 | Survivor space 1 utilization as a percentage of the space's current capacity\. |

| E | Eden space 中Eden 已使用的占当前容量百分比 | Eden space utilization as a percentage of the space's current capacity\. |

| O | Old space 已使用的占当前容量百分比 | Old space utilization as a percentage of the space's current capacity\. |

| M | Metaspace 已使用的占当前容量百分比 | Metaspace utilization as a percentage of the space's current capacity\. |

| CCS | Compressed class 空间利用率 | Compressed class space utilization as a percentage\. |

| YGC | 从应用程序启动到采样时 young generation gc次数 | Number of young generation GC events\. |

| YGCT | 从应用程序启动到采样时Young gc所用时间\(s\) | Young generation garbage collection time\. |

| FGC | 从应用程序启动到采样时Full gc次数 | Number of full GC events\. |

| FGCT | 从应用程序启动到采样时Full gc所用时间\(s\) | Full garbage collection time\. |

| GCT | 从应用程序启动到采样时gc用的总时间\(s\) | Total garbage collection time\. |



(3.1.12) jstat -printcompilation 13050

[wkq@VM_77_25_centos ~]$ jstat -printcompilation 13050
Compiled Size Type Method
7469 63 1 org/apache/logging/log4j/spi/AbstractLogger trace
[wkq@VM_77_25_centos ~]$



<br>



(3.2) 常用jstat命令



(3.2.1) jstat -gc -h5 -t 13050 1000 10



分析进程id为13050的gc情况,每隔1000ms打印一次记录,打印10次停止,每5行后打印指标头部

-gc 查看gc情况

-h5 每5行后打印指标头部

-t 进程启动时间

13050 进程id 也就是linux的pid

1000 每隔1000ms打印一次

10 共打印10行



[wkq@VM_77_25_centos ~]$ jstat -gc -h5 -t 13050 1000 10
Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
217492.5 8512.0 8512.0 0.0 77.3 68160.0 13154.8 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217493.7 8512.0 8512.0 0.0 77.3 68160.0 13154.8 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217494.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217495.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217496.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
Timestamp S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
217497.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217498.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217499.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217500.7 8512.0 8512.0 0.0 77.3 68160.0 14055.9 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
217501.7 8512.0 8512.0 0.0 77.3 68160.0 14068.0 963392.0 60728.2 77732.0 71386.5 11984.0 9862.9 133 2.921 8 0.947 3.868
[wkq@VM_77_25_centos ~]$



我们可以比较 Java 进程的启动时间以及总 GC 时间(GCT 列),或者两次测量的间隔时间以及总 GC 时间的增量,来得出 GC 时间占运行时间的比例。如果该比例超过 20%,则说明目前堆的压力较大;如果该比例超过 90%,则说明堆里几乎没有可用空间,随时都可能抛出 OOM 异常。



(3.2.2) jstat -gcutil -h5 -t 13050 1000 10



分析进程id为13050的gcutil情况,每隔1000ms打印一次记录,打印15次停止,每5行后打印指标头部

-gcutil 查看gcutil情况

-h5 每5行后打印指标头部

-t 进程启动时间

13050 进程id 也就是linux的pid

1000 每隔1000ms打印一次

10 共打印10行



[wkq@VM_77_25_centos ~]$ jstat -gcutil -h5 -t 13050 1000 10
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
217569.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217570.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217571.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217572.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217573.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
Timestamp S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
217574.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217575.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217576.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217577.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
217578.9 0.00 0.91 23.55 6.30 91.84 82.30 133 2.921 8 0.947 3.868
[wkq@VM_77_25_centos ~]$



<br>

<br>



(4) Java配置信息工具 jinfo (Java Configuration Info )



jinfo是实时查看和调整虚拟机各项参数的工具



(4.1) jinfo命令



语法格式

jinfo [ option ] pid



[wkq@VM_77_25_centos ~]$ jinfo -help
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
-flag <name> to print the value of the named VM flag
-flag [+|-]<name> to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
<no option> to print both of the above
-h | -help to print this help message
[wkq@VM_77_25_centos ~]$



[wkq@VM_77_25_centos ~]$ jinfo -option
Usage:
jinfo [option] <pid>
(to connect to running process)
jinfo [option] <executable <core>
(to connect to a core file)
jinfo [option] [server_id@]<remote server IP or hostname>
(to connect to remote debug server)
where <option> is one of:
-flag <name> to print the value of the named VM flag
-flag [+|-]<name> to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-flags to print VM flags
-sysprops to print Java system properties
<no option> to print both of the above
-h | -help to print this help message
[wkq@VM_77_25_centos ~]$



如果遇到 Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for : Operation not permitted,执行 echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope 命令即可



(4.1.1) jinfo pid



[wkq@VM_77_25_centos ~]$ jinfo 13050
Attaching to process ID 13050, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.172-b11
Java System Properties:
jna.platform.library.path = /usr/lib64:/lib64:/usr/lib:/lib:/usr/lib64/dyninst:/usr/lib64/mysql
java.runtime.name = Java(TM) SE Runtime Environment
sun.boot.library.path = /home/wkq/software/jdk1.8.0_172/jre/lib/amd64
java.vm.version = 25.172-b11
es.path.home = /home/wkq/software/elasticsearch-6.6.2
log4j.shutdownHookEnabled = false
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
jna.loaded = true
sun.os.patch.level = unknown
user.country = US
sun.java.launcher = SUN_STANDARD
es.networkaddress.cache.negative.ttl = 10
jna.nosys = true
java.vm.specification.name = Java Virtual Machine Specification
user.dir = /home/wkq/software/elasticsearch-6.6.2
java.runtime.version = 1.8.0_172-b11
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
java.endorsed.dirs = /home/wkq/software/jdk1.8.0_172/jre/lib/endorsed
os.arch = amd64
java.io.tmpdir = /tmp/elasticsearch-5035355569386013893
line.separator =
es.networkaddress.cache.ttl = 60
es.logs.node_name = elasticsearch_001_data
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
io.netty.noKeySetOptimization = true
sun.jnu.encoding = ANSI_X3.4-1968
jnidispatch.path = /tmp/elasticsearch-5035355569386013893/jna-117789/jna8829728915470247279.tmp
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
sun.nio.ch.bugLevel =
es.logs.cluster_name = elasticsearch_test
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-957.21.3.el7.x86_64
user.home = /home/wkq
user.timezone = Asia/Shanghai
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
es.distribution.type = tar
io.netty.recycler.maxCapacityPerThread = 0
user.name = wkq
es.logs.base_path = /home/wkq/software/elasticsearch-6.6.2/logs
java.class.path =
es.path.conf = /home/wkq/software/elasticsearch-6.6.2/config
java.vm.specification.version = 1.8
java.home = /home/wkq/software/jdk1.8.0_172/jre
sun.java.command = org.elasticsearch.bootstrap.Elasticsearch -d
sun.arch.data.model = 64
io.netty.noUnsafe = true
user.language = en
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_172
java.ext.dirs = /home/wkq/software/jdk1.8.0_172/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path =
java.awt.headless = true
java.vendor = Oracle Corporation
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
es.distribution.flavor = default
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
log4j2.disable.jmx = true
sun.cpu.isalist =
VM Flags:
Non-default VM flags: -XX:+AlwaysPreTouch -XX:CICompilerCount=2 -XX:CMSInitiatingOccupancyFraction=75 -XX:ErrorFile=null -XX:GCLogFileSize=67108864 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=87228416 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=87228416 -XX:NumberOfGCLogFiles=32 -XX:OldPLABSize=16 -XX:OldSize=986513408 -XX:-OmitStackTraceInFastThrow -XX:+PrintGC -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:ThreadStackSize=1024 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseGCLogFileRotation -XX:+UseParNewGC
Command line: -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-5035355569386013893 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/wkq/software/elasticsearch-6.6.2 -Des.path.conf=/home/wkq/software/elasticsearch-6.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar
[wkq@VM_77_25_centos ~]$



(4.1.2) jinfo -flag MaxMetaspaceSize pid



[wkq@VM_77_25_centos ~]$ jinfo -flag MaxMetaspaceSize 13050
-XX:MaxMetaspaceSize=18446744073709547520
[wkq@VM_77_25_centos ~]$



(4.1.3) jinfo -flag ThreadStackSize pid

[wkq@VM_77_25_centos ~]$ jinfo -flag ThreadStackSize 13050
-XX:ThreadStackSize=1024
[wkq@VM_77_25_centos ~]$



(4.1.4) jinfo -flag MaxNewSize pid



[wkq@VM_77_25_centos ~]$ jinfo -flag MaxNewSize 13050
-XX:MaxNewSize=87228416
[wkq@VM_77_25_centos ~]$



(4.1.5) jinfo -flag CMSInitiatingOccupancyFraction pid

[wkq@VM_77_25_centos ~]$ jinfo -flag CMSInitiatingOccupancyFraction 13050
-XX:CMSInitiatingOccupancyFraction=75
[wkq@VM_77_25_centos ~]$



(4.1.6) 查看所有JVM参数 java -XX:+PrintFlagsInitial

[wkq@VM_77_25_centos ~]$ java -XX:+PrintFlagsInitial
[Global flags]
uintx AdaptiveSizeDecrementScaleFactor = 4 {product}
uintx AdaptiveSizeMajorGCDecayTimeScale = 10 {product}
...
intx WorkAroundNPTLTimedWaitHang = 1 {product}
uintx YoungGenerationSizeIncrement = 20 {product}
uintx YoungGenerationSizeSupplement = 80 {product}
uintx YoungGenerationSizeSupplementDecay = 8 {product}
uintx YoungPLABSize = 4096 {product}
bool ZeroTLAB = false {product}
intx hashCode = 5 {product}
[wkq@VM_77_25_centos ~]$



(4.1.7) 查看所有支持动态修改的JVM参数 java -XX:+PrintFlagsInitial | grep manageable



[wkq@VM_77_25_centos ~]$ java -XX:+PrintFlagsInitial | grep manageable
intx CMSAbortablePrecleanWaitMillis = 100 {manageable}
intx CMSTriggerInterval = -1 {manageable}
intx CMSWaitDuration = 2000 {manageable}
bool HeapDumpAfterFullGC = false {manageable}
bool HeapDumpBeforeFullGC = false {manageable}
bool HeapDumpOnOutOfMemoryError = false {manageable}
ccstr HeapDumpPath = {manageable}
uintx MaxHeapFreeRatio = 70 {manageable}
uintx MinHeapFreeRatio = 40 {manageable}
bool PrintClassHistogram = false {manageable}
bool PrintClassHistogramAfterFullGC = false {manageable}
bool PrintClassHistogramBeforeFullGC = false {manageable}
bool PrintConcurrentLocks = false {manageable}
bool PrintGC = false {manageable}
bool PrintGCDateStamps = false {manageable}
bool PrintGCDetails = false {manageable}
bool PrintGCID = false {manageable}
bool PrintGCTimeStamps = false {manageable}
[wkq@VM_77_25_centos ~]$



(4.1.7) 调整JVM参数-布尔类型



jinfo -flag [+|-]<name> PID



[wkq@VM_77_25_centos ~]$ jinfo -flag +PrintGC 13050
[wkq@VM_77_25_centos ~]$
[wkq@VM_77_25_centos ~]$ jinfo -flag +PrintGCDetails 13050
[wkq@VM_77_25_centos ~]$

如果没报错则代表生效,加完以后可以通过 jinfo -flags 13050 验证



(4.1.8) 调整JVM参数-数字/字符串类型



jinfo -flag <name>=<value> PID



[wkq@VM_77_25_centos ~]$ jinfo -flag MaxHeapFreeRatio=65 13050
[wkq@VM_77_25_centos ~]$

没报错相当于修改成功,但是怎么验证是否生效,可以通过 jinfo -flags 13050 验证



[wkq@VM_77_25_centos ~]$ jinfo -flags 13050
Attaching to process ID 13050, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.172-b11
Non-default VM flags: -XX:+AlwaysPreTouch -XX:CICompilerCount=2 -XX:CMSInitiatingOccupancyFraction=75 -XX:ErrorFile=null -XX:GCLogFileSize=67108864 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:InitialHeapSize=1073741824 -XX:MaxHeapFreeRatio=65 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=87228416 -XX:MaxTenuringThreshold=6 -XX:MinHeapDeltaBytes=196608 -XX:NewSize=87228416 -XX:NumberOfGCLogFiles=32 -XX:OldPLABSize=16 -XX:OldSize=986513408 -XX:-OmitStackTraceInFastThrow -XX:+PrintGC -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:ThreadStackSize=1024 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseGCLogFileRotation -XX:+UseParNewGC
Command line: -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-5035355569386013893 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/wkq/software/elasticsearch-6.6.2 -Des.path.conf=/home/wkq/software/elasticsearch-6.6.2/config -Des.distribution.flavor=default -Des.distribution.type=tar
[wkq@VM_77_25_centos ~]$

通过 jinfo -flags 13050 获取的结果可以看到



出现 Command failed in target VM 则表示这个flag参数不支持

[wkq@VM_77_25_centos ~]$ jinfo -flag ErrorFile=/home/wkq/es_error_file 13050
Exception in thread "main" com.sun.tools.attach.AttachOperationFailedException: flag 'ErrorFile' cannot be changed
at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:229)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:261)