G1收集器每秒执行50次

时间:2014-05-14 12:30:26

标签: java garbage-collection jvm g1gc

将Java 1.6.0_45与G1一起使用我的应用程序之一几乎无限期地运行G1收集器。除此之外似乎浪费了一些CPU,它还能在我能找到的最低设置下快速填充我的gc日志。

我想知道这里发生了什么。这是正常的吗?

这些是我的JVM标志:

-XX:ParallelGCThreads=4
-XX:+DisableExplicitGC
-XX:+PrintAdaptiveSizePolicy
-XX:MaxGCPauseMillis=500
-XX:+UnlockExperimentalVMOptions
-XX:+AggressiveOpts
-XX:+DoEscapeAnalysis
-XX:+UseCompressedOops
-XX:InitiatingHeapOccupancyPercent=60
-XX:+UseG1GC
-XX:+PrintGCDateStamps
-XX:HeapDumpPath=JavaLogs\uat
-XX:+HeapDumpOnOutOfMemoryError
-Xloggc:jvm.log
-XX:+PrintGC

2014-05-14T08:22:11.173-0400: 495.992: [GC pause (partial) 1177M->1176M(2000M), 0.0178429 secs]
2014-05-14T08:22:11.188-0400: 496.011: [GC pause (partial) 1177M->1176M(2000M), 0.0085317 secs]
2014-05-14T08:22:11.188-0400: 496.021: [GC pause (partial) 1177M->1176M(2000M), 0.0022702 secs]
2014-05-14T08:22:11.204-0400: 496.025: [GC pause (partial) 1177M->1176M(2000M), 0.0028976 secs]
2014-05-14T08:22:11.204-0400: 496.029: [GC pause (partial) 1177M->1176M(2000M), 0.0021763 secs]
2014-05-14T08:22:11.204-0400: 496.032: [GC pause (partial) 1177M->1176M(2000M), 0.0020172 secs]
2014-05-14T08:22:11.204-0400: 496.035: [GC pause (partial) 1177M->1176M(2000M), 0.0020475 secs]
2014-05-14T08:22:11.219-0400: 496.039: [GC pause (partial) 1177M->1176M(2000M), 0.0022187 secs]
2014-05-14T08:22:11.219-0400: 496.042: [GC pause (partial) 1177M->1176M(2000M), 0.0020149 secs]
2014-05-14T08:22:11.219-0400: 496.045: [GC pause (partial) 1177M->1176M(2000M), 0.0021635 secs]
2014-05-14T08:22:11.219-0400: 496.049: [GC pause (partial) 1177M->1176M(2000M), 0.0019517 secs]
2014-05-14T08:22:11.219-0400: 496.052: [GC pause (partial) 1177M->1176M(2000M), 0.0022797 secs]
2014-05-14T08:22:11.235-0400: 496.055: [GC pause (partial) 1177M->1176M(2000M), 0.0020060 secs]
2014-05-14T08:22:11.235-0400: 496.058: [GC pause (partial) 1177M->1176M(2000M), 0.0019567 secs]
2014-05-14T08:22:11.235-0400: 496.062: [GC pause (partial) 1177M->1176M(2000M), 0.0019677 secs]
2014-05-14T08:22:11.235-0400: 496.065: [GC pause (partial) 1177M->1176M(2000M), 0.0019333 secs]
2014-05-14T08:22:11.251-0400: 496.068: [GC pause (partial) 1177M->1176M(2000M), 0.0021960 secs]
2014-05-14T08:22:11.251-0400: 496.071: [GC pause (partial) 1177M->1176M(2000M), 0.0020410 secs]
2014-05-14T08:22:11.251-0400: 496.075: [GC pause (partial) 1177M->1176M(2000M), 0.0019669 secs]
2014-05-14T08:22:11.251-0400: 496.078: [GC pause (partial) 1177M->1176M(2000M), 0.0018926 secs]
2014-05-14T08:22:11.251-0400: 496.081: [GC pause (partial) 1177M->1176M(2000M), 0.0019296 secs]
2014-05-14T08:22:11.266-0400: 496.084: [GC pause (partial) 1177M->1176M(2000M), 0.0025533 secs]
2014-05-14T08:22:11.266-0400: 496.088: [GC pause (partial) 1177M->1176M(2000M), 0.0022381 secs]
2014-05-14T08:22:11.266-0400: 496.091: [GC pause (partial) 1177M->1177M(2000M), 0.0020359 secs]
2014-05-14T08:22:11.266-0400: 496.094: [GC pause (partial) 1178M->1177M(2000M), 0.0018670 secs]
2014-05-14T08:22:11.266-0400: 496.097: [GC pause (partial) 1178M->1177M(2000M), 0.0021041 secs]
2014-05-14T08:22:11.282-0400: 496.101: [GC pause (partial) 1178M->1177M(2000M), 0.0022645 secs]
2014-05-14T08:22:11.282-0400: 496.104: [GC pause (partial) 1178M->1177M(2000M), 0.0020740 secs]
2014-05-14T08:22:11.282-0400: 496.107: [GC pause (partial) 1178M->1177M(2000M), 0.0020746 secs]
2014-05-14T08:22:11.282-0400: 496.110: [GC pause (partial) 1178M->1177M(2000M), 0.0019408 secs]
2014-05-14T08:22:11.282-0400: 496.113: [GC pause (partial) 1178M->1177M(2000M), 0.0021309 secs]
2014-05-14T08:22:11.297-0400: 496.117: [GC pause (partial) 1178M->1177M(2000M), 0.0020609 secs]
2014-05-14T08:22:11.297-0400: 496.120: [GC pause (partial) 1178M->1177M(2000M), 0.0019799 secs]
2014-05-14T08:22:11.297-0400: 496.123: [GC pause (partial) 1178M->1177M(2000M), 0.0019292 secs]
2014-05-14T08:22:11.297-0400: 496.126: [GC pause (partial) 1178M->1177M(2000M), 0.0019674 secs]
2014-05-14T08:22:11.297-0400: 496.129: [GC pause (partial) 1178M->1177M(2000M), 0.0021726 secs]
2014-05-14T08:22:11.313-0400: 496.133: [GC pause (partial) 1178M->1177M(2000M), 0.0021274 secs]
2014-05-14T08:22:11.313-0400: 496.136: [GC pause (partial) 1178M->1177M(2000M), 0.0019959 secs]
2014-05-14T08:22:11.313-0400: 496.139: [GC pause (partial) 1178M->1177M(2000M), 0.0019370 secs]
2014-05-14T08:22:11.313-0400: 496.142: [GC pause (partial) 1178M->1177M(2000M), 0.0019042 secs]
2014-05-14T08:22:11.313-0400: 496.145: [GC pause (partial) 1178M->1177M(2000M), 0.0021778 secs]
2014-05-14T08:22:11.329-0400: 496.149: [GC pause (partial) 1178M->1177M(2000M), 0.0020659 secs]
2014-05-14T08:22:11.329-0400: 496.152: [GC pause (partial) 1178M->1177M(2000M), 0.0019820 secs]
2014-05-14T08:22:11.329-0400: 496.155: [GC pause (partial) 1178M->1177M(2000M), 0.0019167 secs]

3 个答案:

答案 0 :(得分:1)

这不正常。您可能创建了太多对象,GC尝试找到一些可用空间。但是没有任何其他线索我们无法帮助你。尝试一些分析 - 例如jVisualVM,打开采样器,内存并监视对象实例的数量。如果没有内存泄漏,您可以尝试增加应用程序可用的内存。

答案 1 :(得分:1)

这绝对不是“正常”行为。

但是,看起来这正是您选择的GC选项所规定的:

  • 堆大小为2000Mb。 (我不知道这是否是默认大小,或者你是否指定了它。)2000Mb对于看起来具有~120Mb的工作集 1 的应用来说太小了......时间点。

  • 您已告诉JVM在堆达到60%时触发垃圾回收。 2000Mb的60%是〜1200Mb(!)。

那么解决方案是什么?

  • 最好的解决方案是增加堆大小。如果你保持其他JVM参数相同,并且程序工作集保持不变,那么我建议最小堆大小为5Gb;即工作集大小的3倍+ 40%。

  • 如果您准备挤出60%的占用率触发器,则可以使用较小的(超过5Gb)堆运行......但是更长的暂停时间会增加。

  • 如果将“3倍大小”压缩到2倍或更少,则会增加GC运行的频率,并相应地增加GC开销。 (随着GC触发点接近程序的工作集大小,GC开销逐渐增加。)

  • 如果您准备使用吞吐量收集器而不是低暂停收集器,那么GC开销很可能会减少。吞吐量收集器仅在“空间”实际填满时触发。当然,缺点是GC暂停。

如果堆大小和暂停时间要求是一成不变的,那么您唯一可行的选择是尝试减少程序的工作集大小。如果您的程序泄漏内存,请修复泄漏。否则,请查找会降低内存利用率的数据结构更改。


1 - 在此上下文中,工作集是GC运行时可以访问的对象集。

答案 2 :(得分:0)

GC似乎每次调用只能回收1 MB(1177M->1176M)。这显然是浪费时间,你需要给你的过程更多的记忆。然后你会看到像2177M->1176M这样的东西,GC的频率会降低1000倍。