BenchmarkForRails: new benchmarking plugin
Posted by Lance Ivy Fri, 23 Nov 2007 22:00:00 GMT
There’s a new Rails benchmarking plugin in town – BenchmarkForRails. Why? Because with Rails’ benchmarks I never knew how long the request was really taking, including filters and sessions and all that jazz. And because building queries can take longer than executing them, which makes Rails’ DB benchmark somewhat, um, misleading.
This plugin introduces benchmarking for:
- the entire process lifecycle
- session initialization
- before filters (as a group)
- after filters (as a group)
- time spent in ActiveRecord::Base.find
- time spent in a respond_to block
Furthermore, it makes adding more benchmarks incredibly easy. Just follow these simple steps:
- Find the method you want to benchmark. Note the class/module, the method name, and whether it’s an instance or class method. Let’s suppose you want to benchmark the link_to helper in ActionView::Helpers::UrlHelper.
- In your config somewhere (e.g. initializers/custom_benchmarks.rb), tell BenchmarkForRails to watch that method, like so:
BenchmarkForRails.watch(
"link_to calls",
ActionView::Helpers::UrlHelper,
:link_to
)And some sample output, from the log file:
- [0.0489] GET SiteController#index ---- 0.0184 session startup 0.0013 activerecord find 0.0001 before filters 0.0000 after filters 0.0000 respond_to block -------------------- BenchmarkForRails -Errata:
- This has only been tested with Rails 2.0 RC1. I really really doubt it works in Rails 1.2.
- Subversion URL is http://benchmarkforrails.googlecode.com/svn/trunk
Subscribe
Heh, show this to a more design-oriented person and what do I get? Cleaner logfile outputs. New revision looks like:
Yeah, I guess I should have just left a comment here. For the record, I suggested something more like this …
- [0.3140] GET ReceiptsController#new --—-—-—-—-—BenchmarkForRails—Feel free to push that into Rails Core anytime now :)
Yeah, having the overall request time in the title row is pretty nice. I’ve revised the outputter to treat that particular benchmark specially, and updated the sample output in the post above.
When I try to run a rake task I get this. I’m using latest rails svn (2.0.2) http://svn.rubyonrails.org/rails/trunk
rake db:fixtures:generate (in /Users/fred/rails/app_072/trunk) rake aborted! undefined method `watch’ for BenchmarkForRails:Module
Nice work, So useful!!!
Thanks
Hi Frederico, if you still have issues go ahead and post them in the tracker at http://code.google.com/p/benchmarkforrails/issues/list.
>Hi,
Nice plugin but it broke my rake db:migrate. I get the same error as Frederico Araujo:
undefined method `watch’ for BenchmarkForRails:Module using Rails 2.0.2
I reported it to the issues list.
Maxime
The “undefined method `watch’” issue has been found and fixed.
Most people don’t realize its extremely important to know how long a query is..even shaving off thousands of a second can save ridiculous amounts of time.