#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 23 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. 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


11. 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


12. grosser Aug 19, 2008 at 00:12

same here... maybe a gems 1.2 issue


13. 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...


14. Sean Schofield Aug 28, 2008 at 16:52

I had the same problem as everyone above and also failed to get it working with jeremy's gem. I did however get it to work after some investigation.

I took a look at the rails source and it requires ruby-prof 0.6.1. After installing Jeremy's gem I realized it had a slightly different name (jeremy-ruby-prof vs. ruby-prof.) That's probably a github thing but it wasn't satisfying the gem command inside of rails.

So I built the gem from ruby forge source (rake gem, and install manually from the pkg location) and it worked!


15. Lewis Hoffman Sep 03, 2008 at 13:44

Thanks Sean!! that fixed it for me too.


16. Darius Sep 29, 2008 at 14:17

For integration testing you can define session[:user] by adding a second hash, for the session.

get "users/1/edit", {}, {:user_id => 1}

... but this doesn't seem to work for profiling, for some reason.


17. Romain Jul 10, 2009 at 06:33

gotcha : if you are using this with Rails 2.3.2, the request has been discreetly removed so it won't work, as per http://github.com/rails/rails/commit/41af606db385abe429888c5aca8b2e86c8830c24

To add it again manually, follow the instructions at: http://github.com/rails/request_profiler/tree/master

Good luck and thanks again to Ryan for these great contributions!


18. baidu Nov 03, 2009 at 19:14

<a href="http://www.baidu.com">baidu</a>
[url=www.google.com]google[/url]
[url=http://www.sina.com]sina[/url]
[url="http://www.baidu.com"]baidu[/url]
[link=http://www.yahoo.com]yahoo[/link]


19. gucci sunglasses Nov 03, 2009 at 19:16

                               changes just like that of clothes. You want that's out calculate and Canada the shoe amount is

that clutch for their feet. Buy Sand Ultra Tall Ugg Boots or not.


20. Manish Dec 03, 2009 at 21:33

I need graph gem.what should i use for graph.Please tell me which gem is available for graph.
Thanks,
Manish Kumar


22. How to Lose Weight Feb 27, 2010 at 03:21

Hello there, I'm having problems viewing your blog on my iPhone, the comment form isn't showing properly for me. (Just thought you might want to know, I'm typing this from my laptop.)

-Jessica


22. foreign investments Ukraine Mar 13, 2010 at 05:03

Great article and it’s so helpful. But I just can’t see any picture in your blog. Is that my computer problem? But I can see other s’ blog pics. :


23. yyl Mar 17, 2010 at 02:14

The new GHD.IV Styler is one of many hair care products in the most popular, which makes it easy for colleges and universities has straight hair. So you can always have a beautiful flowing straight hair the use of imported PTC heating elements, fast heat up 180 degrees temperature does not harm hair, smooth ceramicsurface, straightened hair

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
Give Back to Open Source