Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the ideal size for an Metaspace for java 8

We are migrating our web application from Java 7 to Java 8. We had defined the PermSize jvm param arguments.

Since Java 8 will ignore this parameters, this are none of use. Metaspace is introduced in Java 8 and default size of it is unlimited(limited to physical memory) with dynamic growth.

My question is do I need to figure out the best values for my web application for metaspace jvm params or default will be a good idea to use?

Update:

More on my web application: My web application is based on struts and spring frameworks. It usually takes 4k requests/min. This application is deployed on tomcat 8.5 and it does not host any other web application. But, there are multiple tomcat instances running on same virtual machine. The current -Xms and -Xmx values are set to 1g.

like image 625
Rishikesh Darandale Avatar asked Aug 10 '17 05:08

Rishikesh Darandale


2 Answers

There are multiple things here that you can consider:

  1. Initial Metaspace Size: Do you see negative and measurable impact when starting up your application because the JVM has to resize the metaspace? Then you should probably set the minimum size. Still I would try to avoid this because this would be a setting that will be easily forgotten when the application grows. -XX:MetaspaceSize=<NNN>

  2. Maximum Metaspace Size: Do you want your application to fail when the metaspace grew to specific size? Or do you want to limit the resources the server takes in this regard? Then you should probably set a maximum size for the metaspace -XX:MaxMetaspaceSize=<NNN>

  3. Metaspace Free Ratio: Do you load many different classes dynamically? Then you could maybe define a free ratio on the metaspace so that always enough space for new classes is available and no resizing will be needed in critical situations. -XX:MinMetaspaceFreeRatio=<NNN> and -XX:MaxMetaspaceFreeRatio=<NNN>

My suggestion would be to stick to the defaults, test it and only react when there is a need to.

like image 116
Absurd-Mind Avatar answered Sep 22 '22 12:09

Absurd-Mind


Holger is right. It's clearly documented here, I may just quote it here.

-XX:MetaspaceSize=size Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used. The default size depends on the platform.

direct quote but the emphasis is mine ;)

like image 34
Hearen Avatar answered Sep 21 '22 12:09

Hearen