New in Rails: a request profiler for profiling your app

In: Ruby|Ruby on Rails|Web development

26 Oct 2007

Jeremy Kemper (aka bitsweat) committed a very useful tool into the Rails trunk not too long ago: a request profiler! It’s a human-friendly wrapper script around the ruby-prof library, a nice ruby code profiler, that lets you run multiple requests against a URI in your application and get a detailed code profile report in text and HTML.

Wanna try it out? Update your vendor/rails to at least revision 8016, run rake rails:update to copy the new script/performance/request script into your app’s script directory, install the ruby-prof gem (sudo gem install ruby-prof), then let it loose on your app.

The options are pretty simple, just pass the script the URI you wanna profile. There’re options for specifying how many requests you want to process, and for profiling POST requests, there’s one for
specifying a POST fixture file.

USAGE: script/performance/request uri [options]
    -u, --uri [URI]                  Request URI. Defaults to http://localhost:3000/
    -n, --times [0000]               How many requests to process. Defaults to 1000.
    -b, --benchmark                  Benchmark instead of profiling
        --method [GET]               HTTP request method. Defaults to GET.
        --fixture [FILE]             Path to POST fixture file
        --open [CMD]                 Command to open profile results. Defaults to "open %s &"
    -h, --help                       Show this help

At the end of the run, you get a text and HTML report with the methods called and the time spent in them. If you haven’t seen a code profile before, it looks something like this:

Rails request profiler text output report

Very nice stuff! It’s extremely convenient to have profiling like this built into Rails itself – personally I’ve not even run any profiling on my Rails code because it seemed like a hassle (though I do run httperf benchmarks and take note the number of requests per second). With code profiling, you can easily see which parts of your code are the bottlenecks and optimize away – it’s a godsend that it’s so easy to do it in Rails!

Anyway, this is all still new stuff I imagine and subject to change (and improvements), but still very exciting for those of us who are hitting performance bottlenecks in our Rails apps (and are not already doing code profiling).

3 Responses to New in Rails: a request profiler for profiling your app


Andy Croll

October 26th, 2007 at 11am

Good topic for next month’s SRB meet?



October 26th, 2007 at 1pm

Sweet! Right when I’m starting to need profiling on performance bottlenecks.


links for 2007-10-31

March 31st, 2008 at 11pm

[…] New in Rails: a request profiler for profiling your app – redemption in a blog (tags: plugin rubyonrails edge) […]