简体   繁体   English

Java 8元空间垃圾回收

[英]Java 8 metaspace garbage collection

A java process that I'm running performs consistently well in the first hour or so that it runs. 我正在运行的Java进程在开始的头一个小时内表现良好,因此可以运行。 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. 我相当确定我可以使用-XX:MaxMetaspaceSize选项来解决此问题。 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 . 您可以尝试设置-XX:MaxMetaspaceExpansion=0 This should force a full GC - releasing dynamically created methods/class data - before attempting to grow the metaspace. 在尝试增加元空间之前,这将强制使用完整的GC-释放动态创建的方法/类数据。 Additionally you can try setting MaxMetaspaceFreeRatio to a lower value than the default to shrink the metaspace itself more after a GC. 另外,您可以尝试将MaxMetaspaceFreeRatio设置为比默认值低的值,以在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. 因此,根据GC的不同,您可能需要进行调整以尽早回收垃圾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM