在开始时管理 JVM OldGen 峰值

To manage JVM OldGen spike at the beginning

我们目前使用的 VMOptions 如下所示,用于我们使用 spring webflux 设计的微服务之一。我们目前为每个 pod 预留了 4 CPU 和 5 GB 的内存。

-Xms4096m -Xmx4096m -Xss512k -XX:+UseG1GC -XX:+UseStringDeduplication -XX:ParallelGCThreads=8 -XX:ConcGCThreads=2 -XX:MaxGCPauseMillis=120 -XX:G1ReservePercent=10

每次我重新部署我们的应用程序并引入一些固定的 QPS 负载时,我观察到 OldGen 上出现了 3 个大峰值,然后它设法稳定地和谐。我从一开始就期待稳定的和谐,但不确定一开始的行为。有没有人也遇到过这样的情况或者知道解决办法。

您观察G1 Adaptive IHOP的效果。

来自G1 tuning guide

The Initiating Heap Occupancy Percent (IHOP) is the threshold at which an Initial Mark collection is triggered and it is defined as a percentage of the old generation size.

G1 by default automatically determines an optimal IHOP by observing how long marking takes and how much memory is typically allocated in the old generation during marking cycles. This feature is called Adaptive IHOP. If this feature is active, then the option -XX:InitiatingHeapOccupancyPercent determines the initial value as a percentage of the size of the current old generation as long as there aren't enough observations to make a good prediction of the Initiating Heap Occupancy threshold. Turn off this behavior of G1 using the option -XX:-G1UseAdaptiveIHOP. In this case, the value of -XX:InitiatingHeapOccupancyPercent always determines this threshold.

默认情况下,-XX:G1AdaptiveIHOPNumInitialSamples等于3。这意味着,G1使用前3个完成的标记周期作为预测最优IHOP的输入。

这样的行为没有错,不需要“修复”任何东西。但是,如果您知道特定应用程序的最佳 IHOP 值,并希望 GC 从一开始就使用它,请关闭 -XX:-G1UseAdaptiveIHOP,然后手动设置 -XX:InitiatingHeapOccupancyPercent