jvm的调优过程分析与理解
背景
- 在什么样的情况下,需要调优?
- 调优的基础指令?
- 调优实战过程的注意事项?
过程
- 需要调优
- 预调优。在具体的业务场景下。比如客户预算只有那么点钱,买个云服务器部署项目。
- 慢,卡顿。在具体的业务场景下。比如项目已经在生产环境跑起来了,出现了,慢或者卡顿现象。
OOM。在具体的业务场景下。比如项目已经在生产环境跑起来了,出现了,OOM情况。
- 调优的基础指令
java -X (查询非标准选项)
-Xmixed 混合模式执行 (默认)
-Xint 仅解释模式执行
-Xbootclasspath:<用 ; 分隔的目录和 zip/jar 文件>
设置搜索路径以引导类和资源
-Xbootclasspath/a:<用 ; 分隔的目录和 zip/jar 文件>
附加在引导类路径末尾
-Xbootclasspath/p:<用 ; 分隔的目录和 zip/jar 文件>
置于引导类路径之前
-Xdiag 显示附加诊断消息
-Xnoclassgc 禁用类垃圾收集
-Xincgc 启用增量垃圾收集
-Xloggc:<file> 将 GC 状态记录在文件中 (带时间戳)
-Xbatch 禁用后台编译
-Xms<size> 设置初始 Java 堆大小
-Xmx<size> 设置最大 Java 堆大小
-Xss<size> 设置 Java 线程堆栈大小
-Xprof 输出 cpu 配置文件数据
-Xfuture 启用最严格的检查, 预期将来的默认值
-Xrs 减少 Java/VM 对操作系统信号的使用 (请参阅文档)
-Xcheck:jni 对 JNI 函数执行其他检查
-Xshare:off 不尝试使用共享类数据
-Xshare:auto 在可能的情况下使用共享类数据 (默认)
-Xshare:on 要求使用共享类数据, 否则将失败。
-XshowSettings 显示所有设置并继续
-XshowSettings:all
显示所有设置并继续
-XshowSettings:vm 显示所有与 vm 相关的设置并继续
-XshowSettings:properties
显示所有属性设置并继续
-XshowSettings:locale
显示所有与区域设置相关的设置并继续
-X 选项是非标准选项, 如有更改, 恕不另行通知。
java -XX:+PrintCommandLineFlags -version (查询当前虚拟机使用了哪个垃圾收集器)
-XX:InitialHeapSize=328369216
-XX:MaxHeapSize=5253907456
-XX:+PrintCommandLineFlags
-XX:+UseCompressedClassPointers
-XX:+UseCompressedOops
-XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
java version “1.8.0_181”
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)jps (查询java 虚拟机的进程有哪些)
10592 Launcher
5456 AttachfileApplication
13416 BrokerStartup
7608 Launcher
10620 NamesrvStartup
13596 Jpsjinfo (查询java进行有哪些基础信息) jinfo 10620
Attaching to process ID 10620, please wait…
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13
Java System Properties:java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.181-b13
sun.boot.library.path = C:\Program Files\Java\jdk1.8.0_181\jre\bin
rocketmq.remoting.version = 355
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
sun.os.patch.level =
sun.java.launcher = SUN_STANDARD
user.script =
user.country = CN
user.dir = E:\resource-code\rocketmq
java.vm.specification.name = Java Virtual Machine Specification
java.runtime.version = 1.8.0_181-b13
java.awt.graphicsenv = sun.awt.Win32GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = C:\Program Files\Java\jdk1.8.0_181\jre\lib\endorsed
line.separator =java.io.tmpdir = C:\Users\Sanding\AppData\Local\Temp\
java.vm.specification.vendor = Oracle Corporation
user.variant =
os.name = Windows 10
sun.jnu.encoding = GBK
java.library.path = C:\Program Files\Java\jdk1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;G:\apache-maven\apache-maven-3.5.3\bin;D:\Git\cmd;C:\Users\Sanding\AppData\Local\Microsoft\WindowsApps;;.
sun.nio.ch.bugLevel =
java.specification.name = Java Platform API Specification
java.class.version = 52.0
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 10.0
user.home = C:\Users\Sanding
user.timezone = Asia/Shanghai
java.awt.printerjob = sun.awt.windows.WPrinterJob
file.encoding = UTF-8
java.specification.version = 1.8
user.name = Sanding
java.class.path = C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;E:\resource-code\rocketmq\namesrv\target\classes;E:\resource-code\rocketmq\client\target\classes;E:\resource-code\rocketmq\common\target\classes;F:\MavenRepository\commons-validator\commons-validator\1.6\commons-validator-1.6.jar;F:\MavenRepository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jar;F:\MavenRepository\commons-digester\commons-digester\1.8.1\commons-digester-1.8.1.jar;F:\MavenRepository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;F:\MavenRepository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;F:\MavenRepository\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar;E:\resource-code\rocketmq\tools\target\classes;E:\resource-code\rocketmq\acl\target\classes;E:\resource-code\rocketmq\logging\target\classes;F:\MavenRepository\commons-codec\commons-codec\1.9\commons-codec-1.9.jar;E:\resource-code\rocketmq\store\target\classes;F:\MavenRepository\io\openmessaging\storage\dledger\0.1\dledger-0.1.jar;F:\MavenRepository\com\beust\jcommander\1.72\jcommander-1.72.jar;F:\MavenRepository\net\java\dev\jna\jna\4.2.2\jna-4.2.2.jar;F:\MavenRepository\com\alibaba\fastjson\1.2.69\fastjson-1.2.69.jar;F:\MavenRepository\org\yaml\snakeyaml\1.19\snakeyaml-1.19.jar;E:\resource-code\rocketmq\srvutil\target\classes;E:\resource-code\rocketmq\remoting\target\classes;F:\MavenRepository\io\netty\netty-all\4.0.42.Final\netty-all-4.0.42.Final.jar;F:\MavenRepository\io\netty\netty-tcnative-boringssl-static\1.1.33.Fork26\netty-tcnative-boringssl-static-1.1.33.Fork26.jar;F:\MavenRepository\commons-cli\commons-cli\1.2\commons-cli-1.2.jar;F:\MavenRepository\ch\qos\logback\logback-classic\1.0.13\logback-classic-1.0.13.jar;F:\MavenRepository\ch\qos\logback\logback-core\1.0.13\logback-core-1.0.13.jar;F:\MavenRepository\org\slf4j\slf4j-api\1.7.7\slf4j-api-1.7.7.jar;D:\IntelliJ IDEA Community Edition 2020.1.2\lib\idea_rt.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = org.apache.rocketmq.namesrv.NamesrvStartup
java.home = C:\Program Files\Java\jdk1.8.0_181\jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.windows.WToolkit
java.vm.info = mixed mode
java.version = 1.8.0_181
java.ext.dirs = C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path = C:\Program Files\Java\jdk1.8.0_181\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_181\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_181\jre\classes
java.vendor = Oracle Corporation
file.separator = \
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.cpu.endian = little
sun.desktop = windows
sun.cpu.isalist = amd64VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=329252864 -XX:MaxHeapSize=5255462912 -XX:MaxNewSize=1751646208 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=109576192 -XX:OldSize=219676672 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
Command line: -javaagent\IntelliJ IDEA Community Edition 2020.1.2\lib\idea_rt.jar=49725
\IntelliJ IDEA Community Edition 2020.1.2\bin -Dfile.encoding=UTF-8
jmap -heap pid(这个指令一般在生产环境不能使用;一般在开发和测试是可以使用的)
jstat -gc pid
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
13312.0 13312.0 0.0 7368.5 80384.0 31455.3 214528.0 80.0 14976.0 14475.0 1920.0 1730.8 1 0.008 0 0.000 0.008S0C:第一个幸存区的大小
S1C:第二个幸存区的大小
S0U:第一个幸存区的使用大小
S1U:第二个幸存区的使用大小
EC:伊甸园区的大小
EU:伊甸园区的使用大小
OC:老年代大小
OU:老年代使用大小
MC:方法区大小
MU:方法区使用大小
CCSC:压缩类空间大小
CCSU:压缩类空间使用大小
YGC:年轻代垃圾回收次数
YGCT:年轻代垃圾回收消耗时间
FGC:老年代垃圾回收次数
FGCT:老年代垃圾回收消耗时间
GCT:垃圾回收消耗总时间jstack pid (看堆栈信息)
2020-12-17 19:32:50
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode):“RemotingExecutorThread_8” #38 prio=5 os_prio=0 tid=0x0000000020d19800 nid=0x34a0 waiting on condition [0x00000000271df000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_7” #37 prio=5 os_prio=0 tid=0x0000000020d1c000 nid=0x2a0c waiting on condition [0x0000000024bbf000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_6” #36 prio=5 os_prio=0 tid=0x0000000020d20800 nid=0x7f0 waiting on condition [0x00000000005ce000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_5” #35 prio=5 os_prio=0 tid=0x0000000020d1f800 nid=0x890 waiting on condition [0x000000000211f000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_4” #34 prio=5 os_prio=0 tid=0x0000000020d17800 nid=0x2e04 waiting on condition [0x00000000007ce000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_3” #33 prio=5 os_prio=0 tid=0x0000000020d19000 nid=0x2f10 waiting on condition [0x00000000270de000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_2” #32 prio=5 os_prio=0 tid=0x0000000020d1c800 nid=0x2fbc waiting on condition [0x0000000025fcf000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“NettyServerCodecThread_2” #21 prio=5 os_prio=0 tid=0x0000000020d18000 nid=0x25c0 waiting on condition [0x0000000024ebe000]
java.lang.Thread.State: TIMED_WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075ca830d0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at io.netty.util.concurrent.SingleThreadEventExecutor.takeTask(SingleThreadEventExecutor.java:269)
at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:39)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at java.lang.Thread.run(Thread.java:748)
“NettyServerNIOSelector_3_2” #16 prio=5 os_prio=0 tid=0x0000000020d1e000 nid=0x2750 runnable [0x0000000024dbe000]
java.lang.Thread.State: RUNNABLEat sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x000000075c92a2f0> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x000000075c92c370> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000075c92a220> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:760)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:401)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at java.lang.Thread.run(Thread.java:748)
“RemotingExecutorThread_1” #31 prio=5 os_prio=0 tid=0x0000000020d1d800 nid=0x8b8 waiting on condition [0x0000000023aaf000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801c60> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“threadDeathWatcher-2-1” #30 daemon prio=1 os_prio=-2 tid=0x000000002027d000 nid=0x3500 runnable [0x000000002279f000]
java.lang.Thread.State: RUNNABLEat java.lang.Thread.isAlive(Native Method)
at io.netty.util.ThreadDeathWatcher$Watcher.notifyWatchees(ThreadDeathWatcher.java:205)
at io.netty.util.ThreadDeathWatcher$Watcher.run(ThreadDeathWatcher.java:143)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:748)
“NettyServerCodecThread_1” #20 prio=5 os_prio=0 tid=0x000000002027c000 nid=0x874 waiting on condition [0x000000002269f000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075ca83590> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at io.netty.util.concurrent.SingleThreadEventExecutor.takeTask(SingleThreadEventExecutor.java:256)
at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:39)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at java.lang.Thread.run(Thread.java:748)
“NettyServerNIOSelector_3_1” #15 prio=5 os_prio=0 tid=0x000000002027b800 nid=0x321c runnable [0x000000002259e000]
java.lang.Thread.State: RUNNABLEat sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x000000075c931100> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x000000075c934080> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000075c931030> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:760)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:401)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at java.lang.Thread.run(Thread.java:748)
“DestroyJavaVM” #29 prio=5 os_prio=0 tid=0x000000002027a000 nid=0x3428 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“FileWatchService” #28 prio=5 os_prio=0 tid=0x000000002027e800 nid=0x504 waiting on condition [0x000000002249f000]
java.lang.Thread.State: TIMED_WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075ca84750> (a org.apache.rocketmq.common.CountDownLatch2$Sync)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1328)
at org.apache.rocketmq.common.CountDownLatch2.await(CountDownLatch2.java:114)
at org.apache.rocketmq.common.ServiceThread.waitForRunning(ServiceThread.java:139)
at org.apache.rocketmq.srvutil.FileWatchService.run(FileWatchService.java:70)
at java.lang.Thread.run(Thread.java:748)
“NettyEventExecutor” #12 prio=5 os_prio=0 tid=0x000000002027d800 nid=0x2388 waiting on condition [0x000000002239f000]
java.lang.Thread.State: TIMED_WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c801af0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.apache.rocketmq.remoting.netty.NettyRemotingAbstract$NettyEventExecutor.run(NettyRemotingAbstract.java:587)
at java.lang.Thread.run(Thread.java:748)
“NettyNIOBoss_1” #14 prio=5 os_prio=0 tid=0x000000002027f000 nid=0x1d2c runnable [0x000000002229e000]
java.lang.Thread.State: RUNNABLEat sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296)
at sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278)
at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
- locked <0x000000075c903960> (a io.netty.channel.nio.SelectedSelectionKeySet)
- locked <0x000000075c9059e0> (a java.util.Collections$UnmodifiableSet)
- locked <0x000000075c903880> (a sun.nio.ch.WindowsSelectorImpl)
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:760)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:401)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
at java.lang.Thread.run(Thread.java:748)
“NSScheduledThread1” #18 prio=5 os_prio=0 tid=0x0000000020278800 nid=0x1cd4 waiting on condition [0x000000002219e000]
java.lang.Thread.State: TIMED_WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c800e88> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
“ServerHouseKeepingService” #13 daemon prio=5 os_prio=0 tid=0x0000000020279000 nid=0x2110 in Object.wait() [0x0000000021a9f000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)at java.lang.Object.wait(Native Method)
at java.util.TimerThread.mainLoop(Timer.java:552)
- locked <0x000000075c808180> (a java.util.TaskQueue)
at java.util.TimerThread.run(Timer.java:505)
“AsyncAppender-Worker-Thread-0” #11 daemon prio=5 os_prio=0 tid=0x000000002051c800 nid=0x1984 waiting on condition [0x00000000209ce000]
java.lang.Thread.State: WAITING (parking)at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000075c810180> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403)
at ch.qos.logback.core.AsyncAppenderBase$Worker.run(AsyncAppenderBase.java:225)
“Service Thread” #10 daemon prio=9 os_prio=0 tid=0x000000001f5ce000 nid=0x176c runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“C1 CompilerThread2” #9 daemon prio=9 os_prio=2 tid=0x000000001f560800 nid=0x374c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“C2 CompilerThread1” #8 daemon prio=9 os_prio=2 tid=0x000000001f54c800 nid=0x1964 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“C2 CompilerThread0” #7 daemon prio=9 os_prio=2 tid=0x000000001f54a800 nid=0x3170 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“Monitor Ctrl-Break” #6 daemon prio=5 os_prio=0 tid=0x000000001f547000 nid=0x3338 runnable [0x000000001fb1e000]
java.lang.Thread.State: RUNNABLEat java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
- locked <0x000000075c81e850> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.readLine(BufferedReader.java:324)
- locked <0x000000075c81e850> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(BufferedReader.java:389)
at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:61)
“Attach Listener” #5 daemon prio=5 os_prio=2 tid=0x000000001e124800 nid=0x240c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“Signal Dispatcher” #4 daemon prio=9 os_prio=2 tid=0x000000001f430800 nid=0x1290 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE“Finalizer” #3 daemon prio=8 os_prio=1 tid=0x000000001e0bf000 nid=0x1fb0 in Object.wait() [0x000000001f41f000]
java.lang.Thread.State: WAITING (on object monitor)at java.lang.Object.wait(Native Method)
- waiting on <0x000000075c808608> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
- locked <0x000000075c808608> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
“Reference Handler” #2 daemon prio=10 os_prio=2 tid=0x0000000002823000 nid=0x371c in Object.wait() [0x000000001f31f000]
java.lang.Thread.State: WAITING (on object monitor)at java.lang.Object.wait(Native Method)
- waiting on <0x000000075c8103d0> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x000000075c8103d0> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
“VM Thread” os_prio=2 tid=0x000000001e097800 nid=0x3564 runnable
“GC task thread#0 (ParallelGC)” os_prio=0 tid=0x0000000002749000 nid=0x93c runnable
“GC task thread#1 (ParallelGC)” os_prio=0 tid=0x000000000274a800 nid=0x2324 runnable
“GC task thread#2 (ParallelGC)” os_prio=0 tid=0x000000000274c000 nid=0x17a4 runnable
“GC task thread#3 (ParallelGC)” os_prio=0 tid=0x000000000274d800 nid=0x3188 runnable
“VM Periodic Task Thread” os_prio=2 tid=0x000000001f626800 nid=0x1e80 waiting on condition
JNI global references: 222
jconsole, jvisulvm (不允许远程连接生产环境。本地开发或者测试是可以连接的。)
一般把生产环境中堆转储文件加载到jvisulvm进行分析。- arthas(阿里开源工具使用) windows上使用
java -jar arthas-boot.jar pid
help
NAME DESCRIPTION
help Display Arthas Help
keymap Display all the available keymap for the specified connection.
sc Search all the classes loaded by JVM
sm Search the method of classes loaded by JVM
classloader Show classloader info
jad Decompile class
getstatic Show the static field of a class
monitor Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.
stack Display the stack trace for the specified class and method
thread Display thread info, thread stack
trace Trace the execution time of specified method invocation.
watch Display the input/output parameter, return object, and thrown exception of specified method invocation
tt Time Tunnel
jvm Display the target JVM information
perfcounter Display the perf counter information.
ognl Execute ognl expression.
mc Memory compiler, compiles java files into bytecode and class files in memory.
redefine Redefine classes. @see Instrumentation#redefineClasses(ClassDefinition…)
dashboard Overview of target jvm’s thread, memory, gc, vm, tomcat info.
dump Dump class byte array from JVM
heapdump Heap dump
options View and change various Arthas options
cls Clear the screen
reset Reset all the enhanced classes
version Display Arthas version
session Display current session information
sysprop Display, and change the system properties.
sysenv Display the system env.
vmoption Display, and update the vm diagnostic options.
logger Print logger info, and update the logger level
history Display command history
cat Concatenate and print files
echo write arguments to the standard output
pwd Return working directory name
mbean Display the mbean information
grep grep command for pipes.
tee tee command for pipes.
profiler Async Profiler. https://github.com/jvm-profiling-tools/async-profiler
stop Stop/Shutdown Arthas server and exit the console.thread
Threads Total: 44, NEW: 0, RUNNABLE: 12, BLOCKED: 0, WAITING: 14, TIMED_WAITING: 8, TERMINATED: 0, Internal threads: 10
ID NAME GROUP PRIORITY STATE %CPU DELTA_TIM TIME INTERRUPT DAEMON
2 Reference Handler system 10 WAITING 0.0 0.000 0:0.000 false true
3 Finalizer system 8 WAITING 0.0 0.000 0:0.000 false true
4 Signal Dispatcher system 9 RUNNABLE 0.0 0.000 0:0.000 false true
5 Attach Listener system 5 RUNNABLE 0.0 0.000 0:0.031 false true
40 arthas-timer system 5 WAITING 0.0 0.000 0:0.000 false true
43 arthas-NettyHttpTelnetBootstr system 5 RUNNABLE 0.0 0.000 0:0.000 false true
44 arthas-NettyWebsocketTtyBoots system 5 RUNNABLE 0.0 0.000 0:0.000 false true
45 arthas-NettyWebsocketTtyBoots system 5 RUNNABLE 0.0 0.000 0:0.000 false true
46 arthas-shell-server system 5 TIMED_WA 0.0 0.000 0:0.000 false true
47 arthas-session-manager system 5 TIMED_WA 0.0 0.000 0:0.000 false true
48 arthas-UserStat system 5 WAITING 0.0 0.000 0:0.000 false true
50 arthas-NettyHttpTelnetBootstr system 5 RUNNABLE 0.0 0.000 0:0.078 false true
51 arthas-command-execute system 5 RUNNABLE 0.0 0.000 0:0.000 false true
6 Monitor Ctrl-Break main 5 RUNNABLE 0.0 0.000 0:0.015 false true
11 AsyncAppender-Worker-Thread-0 main 5 WAITING 0.0 0.000 0:0.015 false true
13 ServerHouseKeepingService main 5 TIMED_WA 0.0 0.000 0:0.000 false true
18 NSScheduledThread1 main 5 TIMED_WA 0.0 0.000 0:0.000 false false
14 NettyNIOBoss_1 main 5 RUNNABLE 0.0 0.000 0:0.046 false false
12 NettyEventExecutor main 5 TIMED_WA 0.0 0.000 0:0.000 false false
28 FileWatchService main 5 TIMED_WA 0.0 0.000 0:0.015 false false
29 DestroyJavaVM main 5 RUNNABLE 0.0 0.000 0:1.625 false false
15 NettyServerNIOSelector_3_1 main 5 RUNNABLE 0.0 0.000 0:0.046 false false
20 NettyServerCodecThread_1 main 5 WAITING 0.0 0.000 0:0.140 false false
30 threadDeathWatcher-2-1 main 1 TIMED_WA 0.0 0.000 0:0.015 false true
31 RemotingExecutorThread_1 main 5 WAITING 0.0 0.000 0:0.078 false false
16 NettyServerNIOSelector_3_2 main 5 RUNNABLE 0.0 0.000 0:0.203 false false
21 NettyServerCodecThread_2 main 5 TIMED_WA 0.0 0.000 0:0.578 false falsethread -b (查询是否有线程发生死锁)如果没有发生则打印如下信息
用处:定位业务代码中,哪些线程发送了死锁。然后,仔细阅读那部分业务代码即可。No most blocking thread found!
dashboard
ID NAME GROUP PRIORITY STATE %CPU DELTA_TIM TIME INTERRUPT DAEMON
-1 C1 CompilerThread2 - -1 - 0.0 0.000 0:1.875 false true
-1 C2 CompilerThread0 - -1 - 0.0 0.000 0:1.750 false true
29 DestroyJavaVM main 5 RUNNABLE 0.0 0.000 0:1.625 false false
-1 C2 CompilerThread1 - -1 - 0.0 0.000 0:1.562 false true
21 NettyServerCodecThread_2 main 5 TIMED_WA 0.0 0.000 0:0.640 false false
50 arthas-NettyHttpTelnetBootstr system 5 RUNNABLE 0.0 0.000 0:0.265 false true
16 NettyServerNIOSelector_3_2 main 5 RUNNABLE 0.0 0.000 0:0.218 false false
20 NettyServerCodecThread_1 main 5 WAITING 0.0 0.000 0:0.140 false false
32 RemotingExecutorThread_2 main 5 WAITING 0.0 0.000 0:0.093 false false
51 arthas-command-execute system 5 RUNNABLE 0.0 0.000 0:0.078 false true
31 RemotingExecutorThread_1 main 5 WAITING 0.0 0.000 0:0.078 false false
Memory used total max usage GC
heap 67M 180M 4455M 1.52% gc.ps_scavenge.count 2
ps_eden_space 57M 78M 1644M 3.49% gc.ps_scavenge.time(ms) 25
ps_survivor_space 0K 13312K 13312K 0.00% gc.ps_marksweep.count 1
ps_old_gen 10M 89M 3341M 0.31% gc.ps_marksweep.time(ms) 36
nonheap 35M 38M -1 90.93%
code_cache 5M 8M 240M 2.40%
metaspace 26M 27M -1 97.20%
compressed_class_space 3M 3M 1024M 0.31%
Runtime
os.name Windows 10
os.version 10.0
java.version 1.8.0_181
java.home C:\Program Files\Java\jdk1.8.0_181\jre
systemload.average -1.00
processors 4
timestamp/uptime Thu Dec 17 19:57:59 CST 2020/2307s- 调优实战过程的注意事项
启动应用服务的时候,需要添加上,-XX:+HeapDumpOnOutOfMemeryError
- jmap -heap pid 不能直接在生产环境中使用,只能在开发和测试环境中使用。
- 采用jvisulvm工具,把发生OOM的时候,dump的文件,加载进来,进行分析,定位问题。
- 生产环境,可以直接使用arthas工具,采集自己需要的信息。比如定位线程死锁。比如定位哪个线程消耗了大量的CPU资源。
小结
- 能够熟练定位jvm相关问题,并能够分析相关信息,定位问题。读代码,找到问题原因,解决问题。
- 理解这些基础指令。不要记忆。需要的时候,可以查询。也可以使用hlep指令,查询。
还没有评论,来说两句吧...