Help me understand ObjectProxyCache and excessive memory usage


#1

Hi,

I’m hoping someone can help me understand why my jruby process is
consuming
so much heap memory. I apologize for not being able to provide code
for a
simple test case, but so far my attempts to recreate in a simple test
case
have failed. I’m hoping either someone will recognize the cause of my
problem or at least help me understand the role of ObjectProxyCache well
enough for me to narrow it down.

I mention ObjectProxyCache because I have taken a heap dump (using jmap)
and
looked at it in the SAP Memory Analyzer and see that
ObjectProxyCache$Segment’s are consuming the majority of my 2GB heap.
(I
kept increasing the heap size to allow my program to complete…)

My program generates custom emails for a large number of users, and each
email is rather large. Most of this is done in ruby, with the result
being
a ruby string. However, the actual SMTP portion is being handled by a
java
class. What i pass the java class is a hash containing the various
aspects
of the mail, ie the recipient, subject, body, etc. The java class
accepts
this hash as a java Map object. Java then submits this map to a
ThreadPoolExecutor to be mailed.

I had been passing the body as a string, but soon realized that this
string
was being converted from utf8 to utf16 (java String) then back to utf8.
Instead, I now pass the body using s.to_java_bytes where s is the ruby
string holding the body.

What I have found is that even when the ThreadPoolExecutor’s queue is
basically empty there are still 16 ObjectProxyCache$Segment instances
full
of ObjectProxyCache$Entry’s each holding a byte[] with one of the long
emails.

They do not seem to be garbage collected, at least not efficiently.
This
happens after my program has been chugging along for a bit, and then my
heap
usage rises to close to the 2GB limit I have set. I built in a throttle
where i sleep the rendering thread for 10seconds when the available heap
space drops too low, and can see that my queue of rendered emails
empties
but the heap space is not freed.

Can anyone explain what’s going on? What causes entries to be added to
the
ObjectProxyCache? Is there something I can do (in either ruby or java
or
both) to ensure they get gc’d?

thanks in advance for any help!

rich


#2

quick note: this is on jruby 1.1.4. I have not yet tried 1.1.5