[rjb-users] Memory Growth

arton arton at e07.itscom.net
Tue Feb 5 09:15:51 EST 2008


Chris,

Rjb uses some global variables -- that means Ruby can't collect the
object -- for holding psuedo classes that reprensents Java Class, this
is according to Rjb's Java meta data holding strategy. The instances are
not held by Rjb, so Ruby can collect them in normal way.
I think it's caused by another reason for example String object that
held entire request body etc.

BTW, you can create debug action for counting all Ruby objects with
ObjectSpace.

def count_objects
  GC.start   # collect unused objects if need
  s = '<ul>'
  i = 0
  ObjectSpace.each_object do |o|
    s << "<li>#{o.class}, #{o.id}, #{o.inspect}</li>"
    i += 1
  end
  s << "</ul><br/>total objects = #{i}"
  render :text => s
end

So, you can check the remain objects in Ruby's object space.

Best regards.

On Tue, 5 Feb 2008 08:28:32 -0500
"Chris O'Meara" <chris at omeara.com>さん wrote:

> Arton,
> 
> Thanks for the insight into RJB's interactions with the JVM.  We're
> profiling our JVM and it appears to be garbage collecting properly.
> 
> I believe the memory growth occurs in the Ruby interpreter.  Can you
> give me any hints regarding how RJB interacts with the Ruby GC?
> 
> Thanks,
> Chris
> 
> On 2/5/08, arton <arton at e07.itscom.net> wrote:
> > Hi Chiris
> >
> > Rjb takes no risk GC strategy. It releases logically safe objects only.
> > That means arguments and returned objects. For example String object
> > that passed from Java methods or Array object that Rjb passes to JVM are
> > released by Rjb and JVM can collect them.
> > In contrast, Rjb never release any meta data such as Classes, Methods,
> > Fields etc. The objects remain in the process forever.
> > So If you import many Java classes, or Classes that defines many methods causes
> > memory growth.
> >
> > Also, you can set special flags to JVM in Rjb::load method's second
> > argument. it taks an array of strings, each string contains one flag.
> > for example
> > Rjb::load nil, ['-verbose:gc']
> > turns on verbose:gc flag (JVM emits GC status to stdout).
> > If you'd like to set some specific flag
> > Rjb::load nil, ['-X***', '-X***' ...]
> >
> > Best regards.
> >
> > On Mon, 4 Feb 2008 20:48:20 -0500
> > "Chris O'Meara" <chris at theomearas.net> wrote:
> >
> > > Hi everyone,
> > >
> > > I have a Rails app which uses RJB extensively to integrate commercial
> > > Java libraries.  Mid-way through the project we encountered some Java
> > > out-of-memory errors and used a Java profiler to track those problems
> > > down and clean them up.  Now we're seeing problems with our Ruby
> > > process growing to varying degrees on various platforms.  (We're
> > > tracking RSS to determine the process size.)  On a MacBook Pro running
> > > Leopard on Mongrel process stays around 100MB; about 200MB on VMWare
> > > running CentOS 4; about 800MB on a 4-way RHEL 4 server.
> > >
> > > Is there anything RJB-specific I should know about as I start
> > > profiling my app?  Any ideas what could cause the Ruby process to grow
> > > so dramatically?  Any profiler suggestions?
> > >
> > > Thanks in advance,
> > > Chris
> > >
> > > _______________________________________________
> > > rjb-users mailing list
> > > rjb-users at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/rjb-users
> >
> > --
> > arton
> >
> > _______________________________________________
> > rjb-users mailing list
> > rjb-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rjb-users
> >
> _______________________________________________
> rjb-users mailing list
> rjb-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rjb-users

-- 
arton



More information about the rjb-users mailing list