No. It could just mean the garbage collector hasn't run yet. In a lot
of cases growth in memory usage is not leaking. That said the GC may
not be able to release memory back to the OS even though it marks the
memory as free for reuse within the same process.
A major source of "leaks" is plain bloat. For example if you app
fetches 5000 database records in memory. They are garbage collected
but they cause the heap grow a lot, which Ruby may not be able to
release back to the OS after GC.
> Or put it another way, is there a possibility that we load too
> much in memory and the memory occupied will be reclaimed later?
Yes.
> Another question is about output of 'passenger-memory-stats', assuming
> the following output of 'passenger-memory-stats':
> ----- Passenger processes -----
> PID VMSize Private Name
> -------------------------------
> 1635 93.3 MB 43.5 MB Rails: /mnt/app/current
> 1639 102.4 MB 52.1 MB Rails: /mnt/app/current
> 25783 3.9 MB 0.2 MB PassengerWatchdog
> 25786 21.5 MB 2.4 MB PassengerHelperAgent
> 25788 20.3 MB 6.0 MB Passenger spawn server
> 25794 9.4 MB 0.4 MB PassengerLoggingAgent
> ### Processes: 6
> ### Total private dirty RSS: 104.61 MB
>
> Does '6.0MB' of 'Passenger spawn server' consists of memory occupied
> by 'Application code' and 'Rails framework code'?
No. It works the other way around.
> And what does the
> memory of every worker process contain?
It shares memory with the ApplicationSpawner provided you use REE.
http://www.modrails.com/documentation/Users%20guide%20Apache.html#spawning_methods_explained
--
Phusion | Ruby & Rails deployment, scaling and tuning solutions
Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)
You will find that pretty much every web application out there except
PHP works this way. They all load the application in memory and keep
the processes around for processing multiple requests, instead of
setting up and tearing down after every request like pretty much only
PHP does. Mongrel, Thin, JBoss, Tomcat, Node.js, etc etc all work like
this.
Ruby or Phusion Passenger does not do that either so I'm not sure what
you're talking about.
Actually what you described is not what you think it is. Ruby's
garbage collector eventually cleans those objects up because they have
no references from the root set, but it does not do that immediately,
nor at the end of the request, but at some time it deems appropriate.
ObjectSpace.each_object just happens to allow you to access dead
objects; it does not mean that they will stay alive. Java's garbage
collector is no different, it does not immediately clean up dead
objects either, nor at the end of the web request, but at some time it
deems appropriate. The difference is that Java does not have an
ObjectSpace.each_object equivalent so there really is no way to access
dead objects.
--
Phusion | Ruby & Rails deployment, scaling and tuning solutions
Web: http://www.phusion.nl/
E-mail: in...@phusion.nl