JVM性能分析利器 JMC 和 JFR


利用 JMC、JFR,可以實現jvm性能問題的准確定位。

JMC:Java Mission Control

Java Flight Recorder(JFR)之前是一個商業特性,現在可以直接使用
類比飛機上的黑匣子


開發環境中,可以使用VisualVM、JProfiler 圖形化工具
attach到jvm進程上, 采集大量數據 ,對應用性能影響很大,不適合在生產環境使用。 



某Java應用性能壓測,TPS 大致 12000 ,
突然 TPS 掉到 6000 多 ,並周期性的在 6000 和 8000 之間波動
經過一系列排查,原來是同事使用 jvisualvm 工具 導致的。
在 高並發 高負載 的壓測場景下 , 
性能監控分析工具的影響比較大 ,尤其是一些可視化工具 ,耗資源
java應用壓測時可關閉jmx端口

jfr不需要在現有應用上添加額外參數、重啟進程等,直接在命令行執行即可實時生效,JVM自帶功能,穩定可靠不影響線上應用運行。


關於jfr的性能消耗
Java Flight Recorder (JFR) is a tool for collecting diagnostic 
and profiling data about a running Java application. 
It is integrated into the Java Virtual Machine (JVM) and causes almost no performance overhead, 
so it can be used even in heavily loaded production environments. 
When default settings are used, both internal testing and customer feedback indicate 
that performance impact is less than one percent. 
For some applications, it can be significantly lower. 
However, for short-running applications (which are not the kind of applications running in production environments), 
relative startup and warmup times can be larger, 
which might impact the performance by more than one percent. 
JFR collects data about the JVM as well as the Java application running on it.   


# 檢查 標志位 
jcmd $pid VM.check_commercial_features
# 先解鎖
jcmd $pid VM.unlock_commercial_features 
jcmd $pid JFR.start  delay=10s duration=1m filename=xxx.jfr

# name=myrecord settings=my-setting
  
# delay 延遲啟動時間,duration 持續采集時間 1分鍾
# settings 使用指定的采集配置  
# $JAVA_HOME/jre/lib/jfr  default.jfc profile.jfc
 
# 
jcmd $pid JFR.stop name=myrecord 

jmc  打開指定的 jfr 文件

主要包括7部分性能報告,分別是一般信息、內存、代碼、線程、I/O、系統、事


GC類型,暫停時間,最短暫停時間、平均暫停時間、最長暫停時間
IO  文件讀寫 套接字讀寫


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM