#98
Mar 24, 2008

Request Profiling

You can use profiling to determine where the performance bottlenecks are in specific Rails actions. Watch this episode for details.
Download (33.6 MB, 10:53)
alternative download for iPod & Apple TV (20.1 MB, 10:53)

Resources

# config/environments/staging.rb
config.cache_classes = true
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching             = true
config.action_view.cache_template_loading            = true

config.log_level = :debug

# lib/products_index_profiler.rb
get '/products'
say "GET #{path}"
$ script/server -e staging
$ sudo gem install ruby-prof
$ RAILS_ENV=staging script/performance/request lib/products_index_profiler.rb

RSS Feed for Episode Comments 14 comments

1. Carl Mar 24, 2008 at 12:36

Good screencast. I'd like to see more information on how you can optimize things once you narrow down the culprits. Maybe a checklist of 'gotchas' or something like that. Especially any that are common and not well known.


2. eddiemoses81@yahoo.com Mar 24, 2008 at 22:52

Great screencast! Thank you very much for all this great information.

Thanks
Eddie Moses


3. myspace proxy Mar 25, 2008 at 08:38

Cool screencasts.. Thanks for sharing.


4. Sam Mar 27, 2008 at 16:10

Little typo detected

should be:
sudo gem install ruby-prof

Great podcast, thanks for the info


5. AJ Mar 27, 2008 at 20:42

@Sam:
its ruby-perf only. (perf => performance)

Nice screencast. I really need to measure performance issues of my app and tutorials like this are of great help. :)


6. Ryan Bates Mar 29, 2008 at 10:34

@Carl, I did some previous episodes on optimization, but they don't cover everything so you can expect some more in the future. You can find them out here.
http://railscasts.com/tags/1

@Sam, thanks. Fixed.


7. Taylor Redden Mar 29, 2008 at 11:47

Hey Ryan, Passenger (mod_rails) is looking for someone to redo there screencast before they release. I think you would be the perfect person for it.

check it out here...
http://izumi.plan99.net/blog/


8. Ryan Bates Mar 29, 2008 at 16:51

@Taylor, thanks for the link. I'll look into doing it. :)


9. JWBnyc Apr 11, 2008 at 16:48

I'm able to run a script, but the files don't contain useful numbers. On Ubuntu (32bit), the first column of profile-flat contains a mix of inf and nan. I'll dig into this, but if you have some guidance, it would be greatly appreciated.

I've tried it on 32-bit Vista, 64-bit Ubuntu & 32-bit Ubuntu. They all report some sort of error. On 64-bit Ubuntu, it aborts with an Integer range error. On Vista, it complains that the files (txt & html) don't exist (though I can open them and see listings for all the methods with no timings). On 32bit Ubuntu, it complains twice about "Could not get a file descriptor referring to the console." These last two create files though the content lacks timings.


10. kino May 23, 2008 at 01:53

In the case of the discipline of pure reason, our a posteriori knowledge, then, teaches us nothing whatsoever regarding the content of the objects in space and time, as is evident upon close examination.


11. Phil Jul 18, 2008 at 05:04

How do you get ruby-prof installed under osx? I've tried under both Tiger and Leopard and I get
No definition for prof_get_cpu_frequency

No definition for prof_set_cpu_frequency

on both


12. Moe Aug 08, 2008 at 03:16

I get the same message No definition for prof_get_cpu_frequency both under OS X (Leopard) & Linux (CentOS 5).

When I run the request script I get following:
Warming up once
0.03 sec, 1 requests, 29 req/sec

Profiling 100x
`gem install ruby-prof` to use the profiler


13. grosser Aug 19, 2008 at 00:12

same here... maybe a gems 1.2 issue


14. grosser Aug 22, 2008 at 22:25

Only thing i found is this:

Please use Jeremy Kamper's ruby-prof :http://github.com/jeremy/ruby-prof/tree/master

gem sources -a http://gems.github.com
sudo gem install jeremy-ruby-prof

but does not work for me either...

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player