不,是GC。
gc永远会是Java程序员需要考虑的不稳定因素之一。对JVM内存的系统级的调优主要的目的是减少GC的频率和Full GC的次数。
而GC的情景复杂又复杂,为了能更深刻的了解内存模型,参考《深入java虚拟机理解》,不定期更新JVM入门。
我自己遇到过一次内存泄漏,但不是线上环境,本地环境出现过一次,后来重新推包解决了,没有复现,那么平时的自用服务器突然内存与磁盘IO暴增,你会如何调优?定位到具体线程后,是因为大对象占用空间造成,还是程序死循环了你如何解决?,关于JVM入门,以及JVM调优整理了地址请转至
https://kkget.github.io/2020/09/24/JVM调优相关
https://kkget.github.io/2020/10/13/JVM从入门到放弃
以上内容不定期更新,今天主要从性能监控工具以及整理关于调优相关部分。
虚拟机性能监控工具
1.jps(JVM Porcess Status Tool)
功能:列出正在运行的虚拟机程序并显示执行主类名称以及进程ID(LVMID ,Local Virtiual Machine Identifier)。
jps -l 输出主类的全类名
jps -v 输出虚拟机启动时的JVM参数
格式 jps [ options ] [ hostid ]
[root@zhaokk shell]# jps -v
2288193 Jps -Denv.class.path=$:CLASSPATH:/opt/soft/jdk/jdk1.8.0_261/lib/ -Dapplication.home=/opt/soft/jdk/jdk1.8.0_261 -Xms8m
2171556 jar -Xmx1024m
2195236 jar -Xmx1024m
2172742 jar -Xmx1024m
1351582 jar -Xmx1024m
2136682 jar -Xmx1024m
2236393 jar
2240457 jar -Xmx1024m
2135436 jar -Xmx1024m
2286668 jar -Xmx1024m
3087 jar -Xmx1024m
2160978 jar -Xmx1024m
2176083 jar -Xmx1024m
2287761 jar
2196085 jar -Xmx1024m
2.jstat(JVM Statistics Monitoring Tool)
jstat [option vmid]
jstat -gc 2764 250 20
[root@zhaokk shell]# jstat -gc 1477 250 20
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
1536.0 1536.0 0.0 110.5 12480.0 2207.5 31084.0 24310.8 24320.0 23552.8 2560.0 2340.8 259 0.589 1 0.051 0.640
jstat -gcutil 2764
[root@zhaokk shell]# jstat -gcutil 1477
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 7.19 19.05 78.21 96.85 91.44 259 0.589 1 0.051 0.640
3.jinfo java配置信息(Configuration Info for java)
格式 jinfo [option] pid
4.jmap (Memory Map for java) java内存映射工具
格式 jmap [option] vmid
jmap -heap
[root@zhaokk shell]# jmap -heap 1477
Attaching to process ID 1477, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.11-b03
using thread-local object allocation.
Mark Sweep Compact GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 482344960 (460.0MB)
NewSize = 1310720 (1.25MB)
MaxNewSize = 160759808 (153.3125MB)
OldSize = 30146560 (28.75MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 14352384 (13.6875MB)
used = 4124624 (3.9335479736328125MB)
free = 10227760 (9.753952026367188MB)
28.738250035673516% used
Eden Space:
capacity = 12779520 (12.1875MB)
used = 4011512 (3.8256759643554688MB)
free = 8768008 (8.361824035644531MB)
31.390161758814102% used
From Space:
capacity = 1572864 (1.5MB)
used = 113112 (0.10787200927734375MB)
free = 1459752 (1.3921279907226562MB)
7.19146728515625% used
To Space:
capacity = 1572864 (1.5MB)
used = 0 (0.0MB)
free = 1572864 (1.5MB)
0.0% used
tenured generation:
capacity = 31830016 (30.35546875MB)
used = 24894208 (23.740966796875MB)
free = 6935808 (6.614501953125MB)
78.20985072706216% used
15847 interned Strings occupying 1391576 bytes.
5.jhat (JVM Heap Analysis Tool)虚拟机堆转快照分析工具 用的比较少
6.jstack java堆栈追踪工具(stack Trace for java) 生成当前的线程快照
格式 jstack [option] vmid
[root@zhaokk bin]# jstack -l 1477
2020-10-20 15:40:50
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.11-b03 mixed mode):
"Attach Listener" #27 daemon prio=9 os_prio=0 tid=0x00007fc928003800 nid=0x446f waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
"http-bio-8080-AsyncTimeout" #25 daemon prio=5 os_prio=0 tid=0x00007fc95039f000 nid=0x5de waiting on condition [0x00007fc92d0cb000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.tomcat.util.net.JIoEndpoint$AsyncTimeout.run(JIoEndpoint.java:153)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
"http-bio-8080-Acceptor-0" #24 daemon prio=5 os_prio=0 tid=0x00007fc95039d800 nid=0x5dd runnable [0x00007fc92d1cc000]
java.lang.Thread.State: RUNNABLE
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:404)
at java.net.ServerSocket.implAccept(ServerSocket.java:545)
at java.net.ServerSocket.accept(ServerSocket.java:513)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:223)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
亦可通过java程序Thread.getAllstackTraces();获得
可视化故障处理工具
Jconsole JHSDB Visual VM JMC
个人常用Jconsole ,Visual VM.
临时有活整理到这...后续有时间再整理
本文分享自微信公众号 - 赵KK日常技术记录(gh_cc4c9f1a9521)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/4217373/blog/4683153