我的服务器在1.8.0_92 6.7上使用CentOS,GC param是'-Xms16g -Xmx16g -XX:+UseG1GC‘。所以默认的InitiatingHeapOccupancyPercent是45,G1HeapWastePercent是5,G1MixedGCLiveThresholdPercent是85。我的服务器的混合GC从7.2GB开始,但是它的清理越来越少,最后老gen保持大于7.2GB,所以它总是尝试做并发标记。最后,所有堆都耗尽,出现了完整的GC。在完成GC后,使用的旧的gen在500 is以下。

我很好奇为什么我的混合GC不能收集更多,看起来活生生的数据不是那么多.
我尝试过打印g1相关的信息,并且发现了许多类似于下面的消息,看起来我的旧代包含了大量的实时数据,但是为什么完整的GC可以收集这么多的数据呢?
G1Ergonomics (Mixed GCs) do not continue mixed GCs, reason: reclaimable percentage not over threshold, candidate old regions: 190 regions, reclaimable: 856223240 bytes (4.98 %), threshold: 5.00 %下面的日志是将InitiatingHeapOccupancyPercent修改为15(启动并发标记为2.4GB)的结果,以加快速度。
### PHASE Post-Marking
......
### SUMMARY capacity: 16384.00 MB used: 2918.42 MB / 17.81 % prev-live: 2407.92 MB / 14.70 % next-live: 2395.00 MB / 14.62 % remset: 56.66 MB code-roots: 0.91 MB
### PHASE Post-Sorting
....
### SUMMARY capacity: 1624.00 MB used: 1624.00 MB / 100.00 % prev-live: 1123.70 MB / 69.19 % next-live: 0.00 MB / 0.00 % remset: 35.90 MB code-roots: 0.89 MB编辑:
在混合GC之后,我尝试触发完整的GC,它仍然可以减少到4xx MB,所以看起来我的旧版本有更多的数据可以收集。

在完全gc之前,混合gc日志是
32654.979: [G1Ergonomics (Mixed GCs) start mixed GCs, reason: candidate old regions available, candidate old regions: 457 regions, reclaimable: 2956666176 bytes (17.21 %), threshold: 5.00 %], 0.1106810 secs]
....
[Eden: 6680.0M(6680.0M)->0.0B(536.0M) Survivors: 344.0M->280.0M Heap: 14.0G(16.0G)->7606.6M(16.0G)]
[Times: user=2.31 sys=0.01, real=0.11 secs]
...
[GC pause (G1 Evacuation Pause) (mixed)
...
32656.876: [G1Ergonomics (CSet Construction) finish adding old regions to CSet, reason: old CSet region num reached max, old: 205 regions, max: 205 regions]
32656.876: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 67 regions, survivors: 35 regions, old: 205 regions, predicted pause time: 173.84 ms, target pause time: 200.00 ms]
32656.992: [G1Ergonomics (Mixed GCs) continue mixed GCs, reason: candidate old regions available, candidate old regions: 252 regions, reclaimable: 1321193600 bytes (7.69 %), threshold: 5.00 %]
[Eden: 536.0M(536.0M)->0.0B(720.0M) Survivors: 280.0M->96.0M Heap: 8142.6M(16.0G)->6029.9M(16.0G)]
[Times: user=2.49 sys=0.01, real=0.12 secs]
...
[GC pause (G1 Evacuation Pause) (mixed)
...
32659.727: [G1Ergonomics (CSet Construction) finish adding old regions to CSet, reason: reclaimable percentage not over threshold, old: 66 regions, max: 205 regions, reclaimable: 857822432 bytes (4.99 %), threshold: 5.00 %]
32659.727: [G1Ergonomics (CSet Construction) finish choosing CSet, eden: 90 regions, survivors: 12 regions, old: 66 regions, predicted pause time: 120.51 ms, target pause time: 200.00 ms]
32659.785: [G1Ergonomics (Mixed GCs) do not continue mixed GCs, reason: reclaimable percentage not over threshold, candidate old regions: 186 regions, reclaimable: 857822432 bytes (4.99 %), threshold: 5.00 %]
[Eden: 720.0M(720.0M)->0.0B(9064.0M) Survivors: 96.0M->64.0M Heap: 6749.9M(16.0G)->5572.0M(16.0G)]
[Times: user=1.20 sys=0.00, real=0.06 secs]编辑: 2016/12/11
我用-Xmx4G将堆从另一台机器中丢弃。
我使用生菜作为我的红宝石客户,它有跟踪功能使用LatencyUtils。它使LatencyStats(包含一些包含近3000个元素的long[] )实例每10分钟弱引用一次(默认情况下,发布后重置延迟为真,https://github.com/mp911de/lettuce/wiki/Command-Latency-Metrics)。因此,经过很长一段时间,它将成为LatencyStats的大量薄弱参考。
在全场比赛之前。



在全场比赛结束后。

目前,我不需要跟踪从莴苣,所以只要禁用它,它不再有完整的GC。但不知道为什么混合gc不能清除它们。
发布于 2019-06-22 19:43:09
嗯,你没有提到你提出的所有论点,但是
你可以试着
-XX:+ScavengeBeforeFullGC您还应该考虑Object的生命周期。您的应用程序Object的生存期是多久,Object的大小是多少。
想一想,看看下面的论点
-XX:NewRatio=n old/new ration (default 2)
-XX:SurvivorRatio=n eden/survivor ratio (default 8)
-XX:MaxTenuringThreshold=n number of times, objects are moved from survivor one to survivor two and vice versa before objects are moved to old-gen (default 15)当默认值为Xms和Xmx时,Xms和Xmx被设置为32 1gb -> gen =16 1gb和新gen 16 1gb -> eden 14 1gb ->幸存者2gb (有两种,每个大小为1gb)。
eden包含由Object实例化的所有new Object。
一个幸存者(对幸存者)总是空的。其他的(来自幸存者)包含Objects,它幸存于一个小gc。
从伊甸园和从幸存者中幸存下来的Object在小的gc中进入幸存者。
如果此“默认配置”的标准大小超过1gb,则Objects将进入旧代。
如果不超过,在15个小的gc(-XX:MaxTenuringThreshold的默认值)之后,Object的会进入旧的代。
通过调整这些值,一定要记住,旧世代必须和新世代一样大或更大,因为gc会导致整个新世代进入旧代。
编辑
你的第一张“旧世代:旧的”图片的时间线会很有帮助。
记住,没有必要做一个完整的gc直到老一代不超过-一个完整的gc导致整个“世界”在一段时间内停止。
在这种情况下,我想说你可以
-Xms和-Xmx降低到8gb-XX:SurvivorRatio值设置为2-XX:MaxTenuringThreshold设置/增加到50你会得到一个新老一代,每个大小都是4gb,
大小为2gb的伊甸园,
两名幸存者,每个都是1gb,
大约有50个小gc,在Object进入老一代之前
https://stackoverflow.com/questions/40680344
复制相似问题