我们的应用程序对延迟至关重要。为了减少 GC 暂停,我们重用对象。在进程开始时,我们分配了很多小对象,然后(几乎)没有分配内存。但是,我仍然看到以下 gc 日志:
2016-12-18T13:51:48.650+0200: 1.085: Total time for which application threads were stopped: 0.0001411 seconds, Stopping threads took: 0.0000203 seconds
2016-12-18T13:51:48.776+0200: 1.210: Total time for which application threads were stopped: 0.0002027 seconds, Stopping threads took: 0.0000183 seconds
2016-12-18T13:51:48.894+0200: 1.328: Total time for which application threads were stopped: 0.0002559 seconds, Stopping threads took: 0.0000194 seconds
2016-12-18T13:51:48.906+0200: 1.341: Total time for which application threads were stopped: 0.0002159 seconds, Stopping threads took: 0.0000199 seconds
2016-12-18T13:51:49.047+0200: 1.482: Total time for which application threads were stopped: 0.0002842 seconds, Stopping threads took: 0.0000208 seconds
据我所知,JVM 会停止进程来运行所有引用并标记对象。这是对的吗?
我还发现此类日志的频率随着时间的推移而减少。所以我认为 GC 调整了一些内部参数,我希望在开始时提供它们。现在我使用以下参数运行进程:
-Xms10240m
-Xmx10240m
-server
-XX:+UseG1GC
-noclassgc
与详细 GC 相关的所有剩余参数。我们的机器有足够的内存来完全避免GC。我该如何向java解释它?
操作系统:Linux,JVM oracle 或 openJDK。
谢谢。
最佳答案
这些不一定是垃圾收集。
当 JVM 打印应用程序线程停止的总时间
时,还有许多其他情况(与 GC 无关)。请参阅the related answer了解详情。
由于类加载和重新编译,非 GC 安全点在应用程序启动时特别频繁。
如果您想跟踪 GC 暂停情况,请使用 -XX:+PrintGCDetails
。
更新
减少非 GC 安全点数量的一些技巧:
-XX:-UseBiasedLocking
完全禁用偏置撤销暂停;-XX:+UnlockDiagnosticVMOptions -XX:GuaranteedSafepointInterval=0
每秒禁用一个强制安全点;-XX:-TieredCompilation
禁用多层编译,从而减少与重新编译相关的安全点的数量。
注意:这只是一个提示,不是生产使用的建议。上述选项可能会对性能产生副作用。
关于java - 如何避免GC暂停?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208167/