java - 如何配置GC不让世界停止?

标签 java performance garbage-collection jvm

假设我有一个 JVM 1.7,它可以正常运行,最大内存为 1G。堆大小。并且仅使用约 0.5G 的堆。

在某些时刻,堆使用量在几分钟内急剧增加(我怀疑负载增加不是内存泄漏)并且 GC (PS MarkSweep) 开始。 GC 运行了大约 30 分钟,并且服务器一直没有响应。

堆统计数据显示,此时 Old Gen 堆使用量增加,Eden 减少,max Survivor 也增加了。

JVM使用默认选项-XX:+UseParallelGC

我会尝试增加堆、限制输入数据大小等。但是我想知道如何调整 GC,使其“停止世界”半小时。我不介意服务器是否变慢,但我不希望它完全停止响应。

如何配置 GC 才不会停止世界

最佳答案

虽然您无法做出保证(除非您使用像 Zing 这样的 VM),但您可以为 GC 提供软目标,GC 将尝试实现该目标。在这里查看更多。 Oracle Technetwork. pt. Ergonomics

XX:MaxGCPauseMillis=.This is interpreted as a hint that pause times of milliseconds or less are desired; ... Note that these adjustments may cause the garbage collector to reduce the overall throughput of the application and in some cases the desired pause time goal cannot be met.

-XX:GCTimeRatio=.The throughput goal is measured in terms of the time spent doing garbage collection vs. the time spent outside of garbage collection (referred to as application time). The goal is specified by the command line option -XX:GCTimeRatio=, which sets the ratio of garbage collection time to application time to 1 / (1 + ). For example, -XX:GCTimeRatio=19 sets a goal of 1/20 or 5% of the total time in garbage collection. The default value is 99, resulting in a goal of 1% of the time in garbage collection.

PS。但是,我认为,如果具有 0.5Gb 堆的应用程序在 GC 中花费 30 分钟,则更有可能该应用程序出现问题,而不是 GC 本身出现问题,除非您尝试在某些旧平台上运行该应用程序。

关于java - 如何配置GC不让世界停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29577993/

相关文章:

MySQL 慢双连接

python - 许多数据帧上的高效 Python Pandas Stock Beta 计算

python - 从词袋数据框到数组的更快的 Python 实现

java - Eclipse 无法加载 liblwjgl64.so

java - 使用 jzlib 创建 gzip 文件

java - 如何使 ListView<ImageView> 不占用超出其需要的空间?

php - 服务器如何判断 session 过期以及如何更改过期时间?

android - 带有 getView() 的 ListView 由于不断的 GC 而过度缓慢?

cassandra - cassandra 中的 G1GC 垃圾收集

java - writeObject() 如何访问 serialPersistantFields