Question

(First of all I don't speak english as well as I wish, I hope you forgive my mistakes :S )

I am very newbie with Ruby and Rails and I am very confused and frustrated because of the memory leaks that I'm having in my application when it runs in production mode.

My server is shutting down my app because it reaches 800MB of memory :O I've google about it and I found that one solution is to use a tool to find leaks: Bleackhouse (I have not managed to install the application) or memprof (no problems to install it) .

I install memprof with:

$ gem install memprof

Once installed I could use it with "irb" and test it, but it is imposible to me to make it run with my Rails 3 application, I know it is because I am very rookie with Rails :(

I have read too much webs, tutos and slides about memprof but I can't found any reference that explains how to install it in Rails.

I add these line to my config/environment.rb

require `gem which memprof/signal`.strip

config/environment.rb:

# -*- encoding : utf-8 -*-

require `gem which memprof/signal`.strip

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
NameApp::Application.initialize!

but when I run my app (Apache + Phusion Passenger) it throws an error:

"Ruby (Rack) application could not be started"

A source file that the application requires, is missing.
It is possible that you didn't upload your application files correctly. Please check whether all your application files are uploaded.
A required library may not installed. Please install all libraries that this application requires.

Error message:
no such file to load --

/path/to/my/app/config/environment.rb   3   in `require'
...

I really don't know why I could run memprof in irb but I can't use it with my Rails application.


Edit 1:

I do the advices that Frederick Cheung give, and now I got it running but I don't know how to start it and write the data to a json file :S

I would be very grateful if someone could help me with this issue.

Thanks.

Was it helpful?

Solution

With the signal stuff you just need to send a URG signal (kill -s URG pid) and it will write to a file in /tmp

You can also use use the middleware that memprof includes (see the documentation

There are two middlewares, that allow you to wrap each request either with Memprof.track or Memprof.trace_request. You can turn them on by putting this in an initialiser (in config/initializers)

require 'memprof/middleware'
config.middlewares.use(Memprof::Middleware)

require 'memprof/tracer'
config.middleware.insert(0, Memprof::Tracer)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top