Java 什么是元数据 GC 阈值以及如何调整它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25251388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:59:50  来源:igfitidea点击:

What is the Metadata GC Threshold and how do I tune it?

javaperformancegarbage-collectionjava-8

提问by Peter Lawrey

In an application I have the following -verbose:gc

在一个应用程序中,我有以下内容 -verbose:gc

[GC (Metadata GC Threshold)  8530310K->2065630K(31574016K), 0.3831399 secs]
[Full GC (Metadata GC Threshold)  2065630K->2053217K(31574016K), 3.5927870 secs]
[GC (Metadata GC Threshold)  8061486K->2076192K(31574016K), 0.0096316 secs]
[Full GC (Metadata GC Threshold)  2076192K->2055722K(31574016K), 0.9376524 secs]
[GC (Metadata GC Threshold)  8765230K->2100440K(31574016K), 0.0150190 secs]
[Full GC (Metadata GC Threshold)  2100440K->2077052K(31574016K), 4.1662779 secs]

What is this "Metadata GC threshold"and how to I reduce it. Note: while the Full GC spends a long time cleaning up, it does not actually clean up much, i.e. it would be better if it didn't do this.

这个“元数据 GC 阈值”是什么以及如何降低它。注意:虽然Full GC 花费很长时间进行清理,但实际上并没有清理多少,也就是说,如果不这样做会更好。

采纳答案by apangin

The log message tells that GC was caused by Metaspaceallocation failure. Metaspaceshold class metadata. They have appearedin Java?8 to replace PermGen.

日志消息告诉 GC 是由元空间分配失败引起的。 元空间保存类元数据。它们已经出现在 Java?8 中以取代PermGen

Here aresome options to tune Metaspaces.
You may want to set one or several of the following options:

以下是一些调整Metaspaces 的选项。
您可能希望设置以下一个或多个选项:

-XX:MetaspaceSize=100MSets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded;

-XX:MetaspaceSize=100M设置分配的类元数据空间的大小,第一次超过时将触发垃圾收集;

-XX:InitialBootClassLoaderMetaspaceSize=32Mto increase the boot class loader Metaspace;

-XX:InitialBootClassLoaderMetaspaceSize=32M增加引导类加载器Metaspace;

-XX:MinMetaspaceFreeRatio=50to make Metaspaces grow more agressively;

-XX:MinMetaspaceFreeRatio=50使元空间更加积极地成长;

-XX:MaxMetaspaceFreeRatio=80to reduce the chance of Metaspaces shrinking;

-XX:MaxMetaspaceFreeRatio=80减少元空间缩小的机会;

-XX:MinMetaspaceExpansion=4Mthe minumum size by which a Metaspace is exanded;

-XX:MinMetaspaceExpansion=4M元空间被扩展的最小大小;

-XX:MaxMetaspaceExpansion=16Mthe maximum size to expand a Metaspace by without Full?GC.

-XX:MaxMetaspaceExpansion=16M在没有 Full?GC 的情况下扩展元空间的最大大小。

回答by Ravindra HV

While there is already an accepted answer, wanted to mention that there is also :

虽然已经有一个公认的答案,但想提一下还有:

-XX:MaxMetaspaceSize=<NNN> where <NNN>is the maximum amount of space to be allocated for class metadata (in bytes).

-XX:MaxMetaspaceSize=<NNN> where <NNN>是为类元数据分配的最大空间量(以字节为单位)。

Also from here,

也是从这里

Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the “MaxMetaspaceSize”.

一旦类元数据使用量达到“MaxMetaspaceSize”,就会触发死类和类加载器的垃圾收集。

There is a list of available options in this post.

这篇文章中有一个可用选项列表 。