Java 8 metaspace garbage collection
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.
user1675642
Updated on July 25, 2022Comments
-
user1675642 over 1 year
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:
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
-
talex over 8 yearsI think you using some framework that generate classes in RunTime. And eventually it get out of control. Solution depends on framework you use.
-
user1675642 over 8 yearsThanks, 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.
-
talex over 8 yearsIt 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.
-
K Erlandsson over 8 yearsWhen you say that performance degrades - what are the symptoms? And have you actually related the metaspace GC to those symptoms?
-
user1675642 over 8 yearsThe 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.
-