In this third article on performance optimization for Ruby on Rails applications, you'll learn how to run the Action Profiler tool and how to start using caching to improve your application's performance. This article is excerpted from chapter 13 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
The Action Profiler and Performance Optimization (Page 1 of 2 )
Running the Action Profiler
The Action Profiler can profile a single Rails action call. It works with any of the three profiler tools for *nix machines: the built-in Ruby profiler, ruby-prof (http://ruby-prof.rubyforge.org/), or ZenProfiler (http://rubyforge.org/projects/zenhacks/). If you want to use ruby-prof or ZenProfiler, you need to install it first.
Here’s an example of running the Action Profiler with the built-in profiler against theshowaction inCatalogController:
You can see from the output that about half of the time is spent scanning strings and creating path names. However, since the built-in profiler presents everything in a flat output, it is hard to know in which part of the application code the time is actually spent. If you want output with call graphs to see where different methods are called from, consider installing ruby-prof.
Note There are currently some compatibility issues between the Action Profiler and both ZenProfiler and ruby-prof. We hope they will be resolved by the time this book hits the shelves.
RAILSBENCH
Another tool for measuring Rails application performance is Railsbench by Rails performance expert Stefan Kaes. You can download if from http://railsbench.rubyforge.org/.
If you’re working on Windows, you might find Railsbench more useful than the Action Profiler. By default, it uses the Windows-only Ruby Performance Validator (www.softwareverify.com/ruby/profiler/ index.html), which is said to be the best Ruby profiler around.