1

When we run junit test, actualy with maven, it use lot of RAM. We have more than 8000 unit tests and it take 30 minutes to finish. Our stack is based on spring and hibernate, unit test are more integration tests because it's used un database (Mariadb) to run. We use also Mockito and Powermokito.

I monitor with JVisualVM : enter image description here enter image description here enter image description here

So I'm very surpising by metaspace usage and classes loaded. I need to optimize that, any advice will be welcome.

UPDATE : We split unit test in 2 tests suites, one with powermock and one without powermock, and we fork surfire lauch. So we get that kind of curve only for powermock jvm (uge increase of metaspace memory). So I found an advice to use @PowerMockIgnore, but we already use it. Anyway spliting in 2 tests suites reduce memory usage.

Mr_Thorynque
  • 1,749
  • 1
  • 20
  • 31

1 Answers1

1

There could be a lot of things under the hood of those graphics, but I would recommend to use Java Flight Recorder as a first step. It allows to see memory allocation per each thread (and who exactly allocated) the memory:

Regarding huge number of classes its better to inspect your heap using Eclipse Memory Analyzer with Calcite plugin that allows to write SQL-related quires to objects from heap dump like

select toString(file) file_str, count(*) cnt, sum(retainedSize(this)) sum_retained, sum(shallowSize(this)) sum_shallow
  from java.net.URL
 group by toString(file)
having count(*)>1
 order by sum(retainedSize(this)) desc

So,

  1. you can easily write queries for count/group by cases.
  2. it would be good to check your transitive dependencies because quite often a lot of unused libraries with their dependencies are exists in project and could be loaded during startup (especially in Spring ecosystem). For mvn based projects you may use command mvn dependency:tree for this https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html or How to get a dependency tree for an artifact?
  3. Please check your code or frameworks that you are using, because maybe they are generating too much classes during work (proxy, etc.), maybe huge number of classes is expected due to architecture of project where you are working...
lazylead
  • 1,453
  • 1
  • 14
  • 26