zoukankan      html  css  js  c++  java
  • 【fullGC】内存监控工具

    什么是fullGC:

         从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC,对老年代GC称为Major GC,而Full GC是对整个堆来说的,在最近几个版本的JDK里默认包括了对永久代即方法区的回收(JDK8中无永久带了),出现Full GC的时候经常伴随至少一次的Minor GC,但非绝对的。

    会引发fullGC的几种情况:https://blog.csdn.net/qq_38384440/article/details/81710887

    分析的话需要从JVM内存结构说起(根据JDK版本会有所调整):

    a、JVM内存模型(图片来自网络):

    b、我们主要看一下堆的构成(图片来自网络):

    1.JVM中堆空间可以分成三个大区,新生代、老年代、永久代

    2.新生代可以划分为三个区,Eden区,两个幸存区

    c、生存情况(图片来自网络):

    定位问题:

    工具:JDK自带的Jmap等工具:%JAVA_HOME%/bin/jmap

    1、查看JVM参数命令:ps -ef |grep java

    2、top命令查看PID

    1、top命令查看PID
    >top
    空闲:
       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                   
      159910 admin     20   0 6593m 2.2g  16m S  3.7 27.4   2:32.04 java                                                                       
      2270 root      20   0  296m  25m 6792 S  1.3  0.3   0:04.93 python 
    普通任务:     
       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND    
    159910 admin     20   0 6725m 2.9g 9452 S 20.6 35.8  59:38.10 java                             
       644 root      20   0  238m 4356 3168 S  1.7  0.1  27:24.38 alisentry_cli
    多线程任务: 
       PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND          
    159910 admin     20   0 6818m 4.4g 9648 S 182.7 54.9  74:45.76 java             
       644 root      20   0  238m 4356 3168 S  0.8  0.1  27:30.43 alisentry_cli 
    

    3、jmap命令
    注意[B 对象 ,这是一个byte数组,可以dump内存中的数据查看内容,会发现实际上就是传输的表数据

    
    >sudo -u admin /opt/taobao/java/bin/jmap -histo:live 159910 | more 
     num     #instances         #bytes  class name
    空闲:
       1:         16391      110613520  [Ljava.lang.Object;
       2:        108702       31890616  [C
       3:          8075       12048648  [B
    普通任务:
       1:          6740      163115880  [B
       2:         16773      110638024  [Ljava.lang.Object;
       3:        110747       32302984  [C
    多线程任务开启:
       1:          9468     2065856344  [B
       2:         18254      110830840  [Ljava.lang.Object;
       3:        130436       34780696  [C
    

    查看堆栈信息:

    启动任务后:
    $sudo -u admin /opt/taobao/java/bin/jmap -heap 159910
    Attaching to process ID 2438, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.66-b60
    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC
    Heap Configuration:
       MinHeapFreeRatio         = 40
       MaxHeapFreeRatio         = 70
       MaxHeapSize              = 4294967296 (4096.0MB)
       NewSize                  = 2147483648 (2048.0MB)
       MaxNewSize               = 2147483648 (2048.0MB)
       OldSize                  = 2147483648 (2048.0MB)
       NewRatio                 = 2
       SurvivorRatio            = 10
       MetaspaceSize            = 268435456 (256.0MB)
       CompressedClassSpaceSize = 1073741824 (1024.0MB)
       MaxMetaspaceSize         = 268435456 (256.0MB)
       G1HeapRegionSize         = 0 (0.0MB)
    Heap Usage:
    New Generation (Eden + 1 Survivor Space):新生代区内存分布,包含伊甸园区+Survivor区
       capacity = 1968570368 (1877.375MB)
       used     = 1965707016 (1874.6442947387695MB)
       free     = 2863352 (2.7307052612304688MB)
       99.85454662700683% used
    Eden Space:Eden区内存分布
       capacity = 1789657088 (1706.75MB)
       used     = 1788720872 (1705.8571548461914MB)
       free     = 936216 (0.8928451538085938MB)
       99.94768740859477% used
    From Space(S1):其中一个Survivor区的内存分布
       capacity = 178913280 (170.625MB)
       used     = 176986144 (168.78713989257812MB)
       free     = 1927136 (1.837860107421875MB)
       98.92286587110806% used
    To Space(S2):另一个Survivor区的内存分布
       capacity = 178913280 (170.625MB)
       used     = 0 (0.0MB)
       free     = 178913280 (170.625MB)
       0.0% used
    concurrent mark-sweep generation(永久代,fullGC位置):
       capacity = 2147483648 (2048.0MB)
       used     = 2147235096 (2047.7629623413086MB)
       free     = 248552 (0.23703765869140625MB)
       99.98842589557171% used
    32663 interned Strings occupying 3788288 bytes.

    查找定位堆栈线程异常:

    FULL GC 详情:sudo -u admin /opt/taobao/java/bin/jstack 159910

    参考地址:

    http://www.cnblogs.com/myna/p/7573843.html

    https://www.cnblogs.com/kongzhongqijing/articles/3621163.html

    top命令,查看java PID 为29037

    ps -ef | grep java 查看java进程及相关参数

    jMap:

    sudo -u admin /opt/taobao/java/bin/jmap -heap 29037
    sudo -u admin /opt/taobao/java/bin/jmap -histo:live 29037 | more 

    sudo -u admin /opt/taobao/java/bin/jmap -heap 29037
    sudo -u admin /opt/taobao/java/bin/jmap -dump:format=b,file=/home/admin/mem.dat 29037
    sudo -u admin /opt/taobao/java/bin/jstack 29037

  • 相关阅读:
    【数据结构】Trie树
    【算法】动态规划经典题之最长公共子序列
    【Leetcode】583. Delete Operation for Two Strings
    【Java】SpringBoot入门学习及基本使用
    【Java学习】调用ByteBuffer.getInt()方法得到808464432
    Install rapyuta Robot Cloud Engine on Ubuntu14.04
    Install rapyuta Robot Cloud Engine on Ubuntu12.04
    怎样下载youtube的字幕
    国内老版本ubuntu更新源地址以及sources.list的配置方法
    配置 ROS 的 apt 源
  • 原文地址:https://www.cnblogs.com/the-fool/p/11054083.html
Copyright © 2011-2022 走看看