java8 metaspacesize,设置MetaspaceSize的准则-Java 8

What is the default value of MetaspaceSize for 64-bit servers? I couldn't find it in the official documentation.

I'm observing that in a server JVM process, at times, the GC frequency becomes high and keeps growing. If I restart the service a few times, it returns to stable. I think its due to the JRE upgrade.

JVM Heap max size is set to be 6GB but when this problem occurs, we see only 3GB heap being used. Metaspace grows by very little and is almost always full. I tried increasing the metaspace to 1GB and it improves the throughput.

I think what is happening is Metaspace by default is set to a very low value and thus GC kicks in. High water mark is continuously increased(again by a very low amount) every time a GC occurs.

I want to set the MetaspaceSize (not sure what is the current value).

Oracle docs say there are no guidelines to know what to set MetaspaceSize to. But is there a way to find out what would be the correct value to set it to?

One hint I got from Oracle docs is this:

If the committed space available for class metadata as a percentage of the total committed space for class metadata is greater than MaxMetaspaceFreeRatio, then the high-water mark will be lowered. If it is less than MinMetaspaceFreeRatio, then the high-water mark will be raised.

But still not able to figure out how to stabilize the GCs..I have three questions:

What is the default MetaspaceSize on 64 bit servers?

What are the default ratios: MaxMetaspaceFreeRatio, MinMetaspaceFreeRatio set to? Answer: It shows Min is 40, Max is 70

How to go about deciding oon a Metaspacesize value?

解决方案

MetaspaceSize is the value when a Full GC will be triggered, its not initial space nor maximum space.

The default value for it is 20MB (at least on jdk-8 to jdk-13):

java -XX:+PrintFlagsFinal -version | grep MetaspaceSize

will produce:

size_t MetaspaceSize = 21807104 // 20MB

This means that when Metaspace reaches 20MB a Full GC will be triggered and if you can avoid it, that would be good.

Considering how much data metaspace can potentially hold (methods, annotations, etc), it seems to me that 20MB is a very small value to start with. Unfortunately, choosing a correct value is not easy.

You have two options, enable gc logging -Xlog:gc and let the app run for some time and then find instances like:

[Full GC (Metadata GC Threshold) ...]

And understand from these what you need to set and how.

Or start the process with:

java -XX:NativeMemoryTracking=detail

connect to the PID via :

jcmd VM.metaspace

And find lines like these:

Virtual space:

Non-class space: 8.00 MB reserved, 4.25 MB ( 53%) committed

Class space: 1.00 GB reserved, 512.00 KB ( <1%) committed

Both: 1.01 GB reserved, 4.75 MB ( <1%) committed

And get the value from Non-class space after the app has been running for at least a day IMHO.

There are various other settings on how to control Metaspace, which you can find out like this:

java -XX:+PrintFlagsFinal -version | grep Metaspace

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值