jvm之判斷ygc耗時和頻率


Step1、找出所查java應用的進程編號

jps -mlv | grep 應用名稱 # 或者 ps -ef | grep 應用名稱
20848 com.lqz.test.Main -Dprogram=APP_/home/lqz/test/bin/.. -Xms4G -Xmx4G

Step2、查看應用的gc概況

  1.  
    $ jstat -gcutil 20848 250 10
  2.  
    S0 S1 E O P YGC YGCT FGC FGCT GCT
  3.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  4.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  5.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  6.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  7.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  8.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  9.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  10.  
    56.25 0.00 52.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  11.  
    56.25 0.00 54.10 34.51 39.51 469204 5176.817 549 111.738 5288.555
  12.  
    56.25 0.00 56.11 34.51 39.51 469204 5176.817 549 111.738 5288.555
  13.  
    $

jstat 詳細用法:jstat - Java Virtual Machine Statistics Monitoring Tool,更多的java工具:JDK Tools and Utilities,更多jdk文檔,請進入傳送門

jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]
  1.  
    -gcutil Option
  2.  
    Summary of Garbage Collection Statistics
  3.  
    Column Description
  4.  
    S0 Survivor space 0 utilization as a percentage of the space's current capacity.
  5.  
    S1 Survivor space 1 utilization as a percentage of the space's current capacity.
  6.  
    E Eden space utilization as a percentage of the space's current capacity.
  7.  
    O Old space utilization as a percentage of the space's current capacity.
  8.  
    P Permanent space utilization as a percentage of the space's current capacity.
  9.  
    YGC Number of young generation GC events.
  10.  
    YGCT Young generation garbage collection time.
  11.  
    FGC Number of full GC events.
  12.  
    FGCT Full garbage collection time.
  13.  
    GCT Total garbage collection time.

Step3、查看應用的運行時間

  1.  
    $ ps -p 20848 -o etime
  2.  
    ELAPSED
  3.  
    7-12:41:04
  4.  
    $
ps -p pid -o etime
  1.  
    CODE HEADER DESCRIPTION
  2.  
    etime ELAPSED elapsed time since the process was started, in the form [[dd-]hh:]mm:ss.

Step4、計算ygc的平均耗時和時間間隔

ygc平均耗時=YGCT/YGC(s)=5176.81/469204=0.011s=11ms

ygc時間間隔=YGC/程序的運行時間=469204/(7*24*60*60 + 12*60*60 + 41*60 + 4 )=0.72s

如果各項參數設置合理,系統沒有超時日志出現,GC頻率不高,GC耗時不高,那么沒有必要進行GC優化;如果GC時間超過1〜3 秒,或者頻繁G C ,則必須優化。如果滿足下面的指標,則一般不需要進行GC:
■ Minor GC執行時間不到50ms;
■ Minor GC執行不頻繁,約10秒一次;
■ Full GC執行時間不到1s;
■ Full GC執行頻率不算頻繁,不低於10分鍾1次。


免責聲明!

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



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