我应该设置 MaxMetaspaceSize 吗? [英] Should I set a MaxMetaspaceSize?
问题描述
因此,在询问了这个问题后,很快就明白重要的问题不是我该怎么做",但是我应该"吗?
So, after asking this question, it quickly became clear that the important question was not "how can I", but "should I"?
我们的客户正在从 Java7 迁移到 Java8(使用 Tomcat7).Java7 需要设置-XX:MaxPermSize
,由于个人需要和使用,一些客户将他们的最大值增加到高于安装程序默认设置的.
We have customers that we are moving from Java7 to Java8 (using Tomcat7). Java7 required setting the -XX:MaxPermSize
, and some customers have increased their max above the default set by the installer due to individual needs and uses.
我是否应该为已定义自定义最大值的客户设置 -XX:MaxMetaspaceSize
(到之前的 -XX:MaxPermSize
设置)?新安装呢?我们应该设置 -XX:MaxMetaspaceSize
吗?
Should I set the -XX:MaxMetaspaceSize
(to the previous -XX:MaxPermSize
setting) for customers who have defined a custom max? What about new installs? Should we set -XX:MaxMetaspaceSize
at all?
这样的决定的利弊是什么?
推荐答案
正如我在上一个答案中评论的那样,对这些内存池设置限制的原因是不同的.
As I commented on the previous answer the reasons for setting a limit on those memory pools is different.
如果您的用户之前增加 MaxPermSize 高于默认值,这可能是为了避免使用 CMS 的 Full GC/并发模式失败,或者因为他们的应用程序确实需要大量永久空间.
If your users previously increased the MaxPermSize above the default that probably was either to avoid Full GCs / concurrent mode failures with CMS or because their applications genuinely needed a lot of perm gen space.
将元空间限制从其有效的无限默认值中减少将用于完全不同的目的:避免无界元空间增长.
Decreasing the the metaspace limit from its effectively infinite default would serve an entirely different purpose: Avoiding unbounded metaspace growth.
问题是这只是一个上限.实际提交的,即 current 元空间大小将更小.事实上,有一个叫做MaxMetaspaceFreeRatio
(默认为70%)的设置,这意味着实际的元空间大小永远不会超过其占用的230%.
The thing is that that's just an upper limit. The actually committed, i.e. current metaspace size will be smaller. In fact, there is a setting called MaxMetaspaceFreeRatio
(default 70%) which means that the actual metaspace size will never exceed 230% of its occupancy.
为了让它增长,它首先必须填满,强制垃圾收集(元空间已满)以尝试释放对象,并且只有当它不能满足其MinMetaspaceFreeRatio
(默认为 40%)目标是在 GC 周期后将当前元空间扩展到不超过占用率的 230%.
And for it to grow it first would have to fill up, forcing a garbage collection (metaspace full) in an attempt to free objects and only when it cannot meet its MinMetaspaceFreeRatio
(default 40%) goal it would expand the current metaspace to no more than 230% of the occupancy after the GC cycle.
因此,在实践中,实际元空间大小应该稳定在与其实际需要接近的范围内,除非应用程序不断泄漏类加载器/类或生成大量动态代码.
So in practice the actual metaspace size should stabilize within a band close relative to its actual need unless the application is continuously leaking classloaders/classes or generating an enormous amount of dynamic code.
TL;DR:限制元空间大小可能是有原因的,但它们可能与设置永久代大小的原始原因不同.因此,应该重新评估需求.
TL;DR: There may be reasons to restrict metaspace size, but they likely are different to the original reasons for setting the perm gen sizes. Therefore the need should be re-evaluated.
这篇关于我应该设置 MaxMetaspaceSize 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!