Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applications is slowing with metaspace growth

I just moved from grails 2.4.3 to grails 2.5.6 and from Java 7 to Java 8. I'm trying to set optimal metaspace size in my app.

Actual metaspace size has big impact on application performance:

Used metaspace and response avg time:

  • 200 MB - 339 ms
  • 300 MB - 380 ms
  • 400 MB - 430 ms
  • 500 MB - 460 ms
  • 600 MB - 530 ms

Metaspace is growing from application start to 620MB in 90 minutes.

This is my actual gc settings:

 -Xms14G -Xmx14G\
 -XX:+UseG1GC\
 -XX:ParallelGCThreads=8\
 -XX:ConcGCThreads=4\
 -XX:MaxGCPauseMillis=200\
 -XX:+UseLargePages\
 -XX:+UseLargePagesInMetaspace\
 -XX:+AlwaysPreTouch\
 -XX:InitialBootClassLoaderMetaspaceSize=512M\
 -XX:MetaspaceSize=512M\
 -XX:MinMetaspaceExpansion=8M\
 -XX:MaxMetaspaceExpansion=32M\
 -XX:+UseStringDeduplication\
 -XX:+ParallelRefProcEnabled\
 -XX:-TieredCompilation\

When MaxMetaspaceSize was set to 512M then after few hours of running my app is slowing down 1 or 2 times for hour. Respons time is around 10 seconds then.

Anyone had such problem? In yours applications metaspace has such impact on performance?

like image 489
jnr Avatar asked Oct 24 '18 11:10

jnr


People also ask

How do I fix Metaspace error?

OutOfMemoryError: Metaspace error is thrown. To mitigate the issue, you can increase the size of the Metaspace by adding the -XX:MaxMetaspaceSize flag to startup parameters of your Java application. For example, to set the Metaspace region size to 128M, you would add the following parameter: -XX:MaxMetaspaceSize=128m .

Why does Metaspace increase?

Metaspace by default auto increases its size depending on the underlying OS. Contiguous Java Heap Memory. Native Memory(provided by underlying OS). Inefficient garbage collection.

What is Metaspace used for?

Metaspace is a native memory region that stores metadata for classes. As a class is loaded by the JVM, its metadata (i.e. its runtime representation in the JVM) is allocated into the Metaspace. The Metaspace occupancy grows as more and more classes are loaded.


1 Answers

Have you profiled your app?

I'd say that Metaspace garbage collection was involved here. It collects dead classes and classloaders and it's triggered once the class metadata usage reaches the MaxMetaspaceSize (which was narrowed by -XX:MaxMetaspaceSize).

like image 185
Michal_Szulc Avatar answered Oct 31 '22 18:10

Michal_Szulc