Java 8元数据空间垃圾收集 [英] Java 8 metaspace garbage collection
问题描述
我运行的java进程在第一个小时内运行良好,或者运行得很好。但是,性能会迅速降低。在分析时,我发现metaspace垃圾收集发生得非常频繁,直到小时标记,然后失控:
我确信我可以使用-XX:MaxMetaspaceSize选项修复此问题。不过,我想了解更多关于这种行为可能发生的原因。我无法想象垃圾收集算法为什么会像这样。有没有人有更好的解决方案的解释或建议?谢谢
您可以尝试设置 -XX:MaxMetaspaceExpansion = 0
。这应该强制一个完整的GC - 释放动态创建的方法/类数据 - 在尝试扩展元组空间之前。此外,您可以尝试将 MaxMetaspaceFreeRatio
设置为比默认值更低的值,以在GC之后缩小元数据空间本身。
有关其他元数据相关选项,请参见此答案。
Metaspace集合本身依赖于被垃圾收集器卸载的类。因此,根据您使用GC调整垃圾回收时间可能会有所帮助。
A java process that I'm running performs consistently well in the first hour or so that it runs. However, performance then rapidly degrades. When profiling I found that the metaspace garbage collection happened fairly frequently until the hour mark and then got out of control:
I'm fairly sure I'll be able to fix this using the -XX:MaxMetaspaceSize option. However, I'd like to know more about why this behaviour might be occurring. I can't imagine why the garbage collection algorithm would behave like this. Does anyone have an explanation or advice about a better fix? Thanks
You can try setting -XX:MaxMetaspaceExpansion=0
. This should force a full GC - releasing dynamically created methods/class data - before attempting to grow the metaspace. Additionally you can try setting MaxMetaspaceFreeRatio
to a lower value than the default to shrink the metaspace itself more after a GC.
See this answer for other metaspace related options.
Metaspace collection itself relies on classes being unloaded by the garbage collector. So depending on the GC you're using tweaking that to reclaim garbage sooner might also help.
这篇关于Java 8元数据空间垃圾收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!