java - 在开始时管理 JVM OldGen 峰值

标签 java performance garbage-collection jvm

我们目前使用的 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

JVM Graph

每次我重新部署我们的应用程序并引入一些固定的 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手动。

关于java - 在开始时管理 JVM OldGen 峰值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67296753/

相关文章:

java - 包级注释是否适用于子包?

java - 如何从ZK页面调用后端方法?

mysql - 如何使内部连接高效的mysql

performance - URL 重写会阻止 IIS 的静态文件缓存吗?

Android解除分配位图进入 "unknown"内存

java - 为什么GC不清除Dialog引用?

java - 带符号的拉丁正则表达式

java - 多线程和 Selenium

java - 你能排除一个对象不被 Java 中的垃圾收集器跟踪吗?

java - 数据库问题