9

A java process that I'm running performs consistently well in the first hour or so that it runs. However, performance then rapidly degrades. When profiling I found that the metaspace garbage collection happened fairly frequently until the hour mark and then got out of control:

enter image description here

I'm fairly sure I'll be able to fix this using the -XX:MaxMetaspaceSize option. However, I'd like to know more about why this behaviour might be occurring. I can't imagine why the garbage collection algorithm would behave like this. Does anyone have an explanation or advice about a better fix? Thanks

user1675642
  • 747
  • 2
  • 5
  • 15
  • I think you using some framework that generate classes in RunTime. And eventually it get out of control. Solution depends on framework you use. – talex Jul 23 '15 at 14:07
  • Thanks, and yes I am. That occurred to me, but the rate at which classes are generated doesn't seem to be changing. All that seems to change is that the frequency of the gc decreases. – user1675642 Jul 23 '15 at 14:14
  • It is probably some JVM heuristics. It's try to find better parameters like max size. Also it is looks like stroboscopic effect. Size of metaspace measured at some specific moment of time. When frequency of GC is about the same as frequency of measurement some strange effects can occur. – talex Jul 23 '15 at 14:44
  • When you say that performance degrades - what are the symptoms? And have you actually related the metaspace GC to those symptoms? – K Erlandsson Jul 23 '15 at 19:36
  • The symptoms are that the process does what it does much slower. The memory used by the process also starts increasing. The change is correlated with the change seen in the graph. I'm interested in an explanation of the graph above, even if it is in fact unrelated to my performance problem. – user1675642 Jul 24 '15 at 11:50

1 Answers1

9

You can try setting -XX:MaxMetaspaceExpansion=0. This should force a full GC - releasing dynamically created methods/class data - before attempting to grow the metaspace. Additionally you can try setting MaxMetaspaceFreeRatio to a lower value than the default to shrink the metaspace itself more after a GC.

See this answer for other metaspace related options.

Metaspace collection itself relies on classes being unloaded by the garbage collector. So depending on the GC you're using tweaking that to reclaim garbage sooner might also help.

Community
  • 1
  • 1
the8472
  • 40,999
  • 5
  • 70
  • 122