javaGC笔记-成都快上网建站

javaGC笔记

以hbase为例:在hbase的配置文件路径下,设置了GC log输出路径/app/hbase-config/hbase-env.sh

目前创新互联已为上千多家的企业提供了网站建设、域名、雅安服务器托管成都网站托管、企业网站设计、商城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

export HBASE_OPTS="-Xmx16384m -Xms16384m -Xmn8192m -XX:PermSize=160M -XX:MaxPermSize=160M -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=3  -XX:+CMSParallelRemarkEnabled -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -XX:PrintFLSStatistics=1 -Xloggc:/app/hbase/logs/hbase_gc.log $HBASE_OPTS"

可以查询到log的相关信息

#jstat -gccause 79751 1000 1000 //获取GC相关指标,表示每1000毫秒查询一次79751垃圾收集状况。
Usage: jstat -help|-options
       jstat -

    S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00   8.98  11.16  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  12.79  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  14.94  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  16.04  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  17.98  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  20.34  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  21.83  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC
  0.00   8.98  22.64  69.83  12.33    156   50.788    16  280.103  330.891 unknown GCCause      No GC

E列代表
O E-->O 新生代转移到老代,O积累到80%就会触发full gc

具体意思如下:
E(表示,Eden),代表这台服务器的新生代Eden区使用了11.16的空间,
S0 S1 两个Survivor区(S0,S1表示Survivor0、Survivor1),Survivor0里面是空的,Survivor1占了8.98%

老年代(O,表示old) 和永久带(P,表示Permanent)分别使用了69.83% 和12.33%的空间。
程序运行以来共发生Minor GC(YGC ,表示young gc)156次,总耗时50.788秒;
发生Fulle GC (FGC,表示full GC )16次,full GC总耗时(FGCT,表示full gc time)为330.891秒,总的GC总耗时(GCT,表示GC Time)为330.891秒
LGCC Cause of last Garbage Collection.
GCC Cause of current Garbage Collection.

Java 6 JDK输出如下:
[hadoop@0321 logs]$ jmap -heap 29877

Attaching to process ID 29877, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 20.45-b01

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 21474836480 (20480.0MB)
   NewSize          = 4294967296 (4096.0MB)
   MaxNewSize       = 4294967296 (4096.0MB)
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 67108864 (64.0MB)
   MaxPermSize      = 67108864 (64.0MB)

Heap Usage:
New Generation (Eden + 1 Survivor Space):
   capacity = 3865509888 (3686.4375MB)
   used     = 481048576 (458.763671875MB)
   free     = 3384461312 (3227.673828125MB)
   12.444634470949257% used
Eden Space:
   capacity = 3436052480 (3276.875MB)
   used     = 481048576 (458.763671875MB)
   free     = 2955003904 (2818.111328125MB)
   14.00003576196834% used
From Space:
   capacity = 429457408 (409.5625MB)
   used     = 0 (0.0MB)
   free     = 429457408 (409.5625MB)
   0.0% used
To Space:
   capacity = 429457408 (409.5625MB)
   used     = 0 (0.0MB)
   free     = 429457408 (409.5625MB)
   0.0% used
concurrent mark-sweep generation:
   capacity = 12884901888 (12288.0MB)
   used     = 0 (0.0MB)
   free     = 12884901888 (12288.0MB)
   0.0% used
Perm Generation:
   capacity = 67108864 (64.0MB)
   used     = 21153816 (20.173851013183594MB)
   free     = 45955048 (43.826148986816406MB)
   31.521642208099365% used
  • Eden from to 3个加起来为Young 区

[hbase@0321 ~]$ jps
10424 Jps
8229 HRegionServer

[hbase@0321 ~]$ jmap -heap 8229
Attaching to process ID 8229, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.71-b01

using thread-local object allocation.
Garbage-First (G1) GC with 6 thread(s)

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 25769803776 (24576.0MB)
NewSize = 1363144 (1.2999954223632812MB)
MaxNewSize = 17592186044415 MB
OldSize = 5452592 (5.1999969482421875MB)
NewRatio = 2
SurvivorRatio = 8
PermSize = 16777216 (16.0MB)
MaxPermSize = 83886080 (80.0MB)
G1HeapRegionSize = 8388608 (8.0MB)

Heap Usage:
G1 Heap:
regions = 3072
capacity = 25769803776 (24576.0MB)
used = 20409483264 (19464.0MB)
free = 5360320512 (5112.0MB)
79.19921875% used
G1 Young Generation:
Eden Space:
regions = 89
capacity = 1182793728 (1128.0MB)
used = 746586112 (712.0MB)
free = 436207616 (416.0MB)
63.12056737588652% used
Survivor Space:
regions = 20
capacity = 167772160 (160.0MB)
used = 167772160 (160.0MB)
free = 0 (0.0MB)
100.0% used
G1 Old Generation:
regions = 2324
capacity = 24419237888 (23288.0MB)
used = 19495124992 (18592.0MB)
free = 4924112896 (4696.0MB)
79.83510821023704% used
Perm Generation:
capacity = 50331648 (48.0MB)
used = 42303832 (40.344078063964844MB)
free = 8027816 (7.655921936035156MB)
84.05016263326009% used

G1 GC笔记:

关于最大gc停顿时间
在做minor gc和mixed gc时,收集器会在内存中维系一个remembered set,这个set包含了heap中所有对象的引用,用以确定哪些可以被回收。
每次gc时,g1会通过一个预测模型来计算每个region进行回收的时间,从而从中选出停顿时间在MaxGCPauseMillis之内的region进行垃圾回收
 

关于mixed gc

mixed gc是一种既回收young区,也回收old区的垃圾回收方式,它触发的条件是-XX:InitiatingHeapOccupancyPercent,mixed gc的目的就是为了延迟full gc的产生

同理YGC指的是回收young的垃圾回收方式

Full GC 指的是回收Old去的垃圾回收方式,因为old区比较大,导致GC时间比较长,并且在GC期间java进程停止对外相应,并且自身也不对外响应,导致regionserver无法向zookeeper注册心跳信息,超过zookeeper ( zookeeper.session.timeout) session时间,就会被zookeeper置为dead。

Hbase G1参数调整:

待修改的参数,修改GC的参数需要重启集群,安排在下次重启。

-XX:ConcGCThreads=12并发标记的执行线程数 =================== 测试数据ConcGCThreads 不能大于-XX:ParallelGCThreads,否则会报错
-XX:InitiatingHeapOccupancyPercent=60  堆占用了多少的时候就触发GC,默认为45
-XX:ParallelGCThreads=12 30

[hbase@0321 ~]$ jstat -gccapacity 61540
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC
0.0 52428800.0 2490368.0 0.0 294912.0 2195456.0 0.0 52428800.0 44695552.0 44695552.0 16384.0 81920.0 49152.0 49152.0 2 0

GC 常见命令:

[hbase@ 0321 ~]$ jmap -heap 61540

Attaching to process ID 61540, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.71-b01

using thread-local object allocation.
Garbage-First (G1) GC with 30 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 53687091200 (51200.0MB)
   NewSize          = 1363144 (1.2999954223632812MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5452592 (5.1999969482421875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 16777216 (16.0MB)
   MaxPermSize      = 83886080 (80.0MB)
   G1HeapRegionSize = 16777216 (16.0MB)

Heap Usage:
G1 Heap:
   regions  = 2880
   capacity = 48318382080 (46080.0MB)
   used     = 2519304864 (2402.5963439941406MB)
   free     = 45799077216 (43677.40365600586MB)
   5.213967760403951% used
G1 Young Generation:
Eden Space:
   regions  = 7
   capacity = 2248146944 (2144.0MB)
   used     = 117440512 (112.0MB)
   free     = 2130706432 (2032.0MB)
   5.223880597014926% used
Survivor Space:
   regions  = 18
   capacity = 301989888 (288.0MB)
   used     = 301989888 (288.0MB)
   free     = 0 (0.0MB)
   100.0% used
G1 Old Generation:
   regions  = 126
   capacity = 45768245248 (43648.0MB)
   used     = 2099874464 (2002.5963439941406MB)
   free     = 43668370784 (41645.40365600586MB)
   4.588059805705051% used
Perm Generation:
   capacity = 50331648 (48.0MB)
   used     = 42610464 (40.636505126953125MB)
   free     = 7721184 (7.363494873046875MB)
   84.65938568115234% used

13018 interned Strings occupying 1388240 bytes.

[hbase@0321 ~]$ jstat -gccause -h 10 61540 1000 1000

  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00 100.00  92.54  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00  92.54  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00  92.54  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00  93.28  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00  93.28  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00  93.28  20.26  85.06     16    1.794     0    0.000    1.794 G1 Evacuation Pause  No GC
  0.00 100.00   1.42  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   1.42  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   3.55  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  S0     S1     E      O      P     YGC     YGCT    FGC    FGCT     GCT    LGCC                 GCC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC
  0.00 100.00   4.26  21.24  85.06     17    1.877     0    0.000    1.877 G1 Evacuation Pause  No GC

#jstat -gcutil 27912 1s 50


网站名称:javaGC笔记
URL网址:http://kswjz.com/article/ijhjoi.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流