Very large retained heap size for org.jruby.RubyRe

2019-09-11 16:33发布

问题:

We have analysed a heap dump file for our application (running on Tomcat with jruby 1.7.8).

It shows us that the retained heap size is very large (439,459,128) for the class org.jruby.RubyRegexp$RegexpCache. This is 48% of our memory usage

Looking at the source code for that file it is 3 final static object created at startup (patternCache / quotedPatternCache / preprocessedPatternCache)

This seems to be a pretty core part of JRuby. My question is, is it normal to have such a large percentage of the heap to be dedicated to this cache?

回答1:

it probably cached most of the Regexp objects through out the Rails/gems/user-code source ... so it might be quite huge. unless you run into a leak (out-of-memory issue) it's all fine since the actual caches are wrapped in a soft reference, that means until there's enough memory (heap size) they will be held from garbage collection but as soon as you allocate a chunk that does not fit all (or some) of those caches may get garbage collected.