.

Coffee Powered

code and content

Announcing Scrap

I do a lot of memory and garbage analysis on my Rails apps, and in upgrading to Rails 2.3, I discovered a practical use for the new Rails Metal middleware. Dumping memory stats to my log was just sorta unreadable in a practical scenario, and was more or less entirely unusable in production. Fortunately, Metal provides a really easy way to output readable information to the browser without invoking the full Rails stack. (It’s also an excuse to write a Metal endpoint because it’s new and shiny, but that’s beside the point.)

It’s up at github – installation is dead easy (assuming you’re on Rails 2.3+, of course) – just install the plugin, restart your app, and hit <your url>/stats/scrap in your browser. Bam, instant juicy memory goodness about your app at your fingertips. If you’d like an example of the output, good news! Check it out at http://tachyonsix.com/scrap.htm.

You can use it to troubleshoot heap leaks – just run a few requests, hit your Scrap URL, and see what your deltas look like. Seeing a huge growth in a certain type of object? Chances are pretty good that you have a heap leak, and can start tracking it down.

The request history can help you locate certain actions that might be causing spikes in memory usage. It’ll show the last N requests, along with memory and heap statistics before each request. If there’s a consistent memory usage leap after a certain action, chances are that it’s doing something naughty.

Want to get a bigger picture on what objects are hanging around? You can use the config/scrap.yml file to get Scrap to spit out more detailed reports on instances of a given class. There’s full documentation on it in the README.

Anyhow, give it a shot, let me know what you think.

  • http://neeraj.name Neeraj

    Thank you. This would be of tremendous help to me.

  • http://semanticart.com Jeff

    Fantastic idea

  • http://holmwood.id.au/~lindsay Lindsay Holmwood

    This is a fantastic way to instrument performance metrics. A JSON output would be pretty handy too.

    Top marks! :-)

  • Luis Cipriani

    This is great! But, you need to use a GC Patched ruby, right? I have experienced a lot of problems when I tried to prepare and run this environment at work (2 ruby version installed in one machinne, one with the patch just for memory profiling, this didn't work for our legacy applications). Could you share with us the procedure to install this GC patched ruby? Thanks

  • http://welcometonewnepal.com Millisami

    Hi, I've deployed my new Rails 2.3.2 app with passenger and REE in 256 MB slice at slicehost and the app is ridiculously slow. Hardly 1 req/s or 0.67req/s.

    Have tried various ways to figure out but still lost and I installed this scrap plugin and it shows the infos but I'm not being able to interpret the result. Can you plz suggest me by looking at the scrap at http://welcometonewnepal.com/stats/scrap
    Its killing my Rails love coz its my first app.

  • Jens Rasmussen

    Millisami, try switching to Nginx+Passenger instead of Apache, that saved me about 700MB… on 256MB your app is probably swapping mem heavily.

  • Jens Rasmussen

    Got this error:

    DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead.. (called from memcheck at /Users/jens/projects/cbcl/vendor/plugins/scrap/app/metal/scrap.rb:171)

  • Ajit singh

    Hi

    I have just installed your plugin but am not getting any results back. Following is the error I am getting:

    cat: /proc/17469/stat: No such file or directory

    cat: /proc/17469/stat: No such file or directory

    Respond to? false

    cat: /proc/17469/stat: No such file or directory

    true

    true

    {"show_fields"=>["id", "updated_at"], "foo"=>"bar", "print_objects"=>true}

    SQL (0.1ms) SET NAMES 'utf8'

    SQL (0.1ms) SET SQL_AUTO_IS_NULL=0

    DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead.. (called from memcheck at /Users/ajit/Sites/gshiftlabs/vendor/plugins/scrap/app/metal/scrap.rb:171)

    DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead.. (called from memcheck at /Users/ajit/Sites/gshiftlabs/vendor/plugins/scrap/app/metal/scrap.rb:172)

    DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead.. (called from memcheck at /Users/ajit/Sites/gshiftlabs/vendor/plugins/scrap/app/metal/scrap.rb:171)

    DEPRECATION WARNING: ActiveSupport::JSON::CircularReferenceError is deprecated! Use ActiveSupport::JSON::Encoding::CircularReferenceError instead.. (called from memcheck at /Users/ajit/Sites/gshiftlabs/vendor/plugins/scrap/app/metal/scrap.rb:172)