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


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


20. 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. :


21. louis vuitton speedy bag Jul 04, 2010 at 23:16

Thank you share


22. neverfull Jul 04, 2010 at 23:17

Nice ,Thank you


23. louis vuitton damier neverfull mm Jul 14, 2010 at 00:59

this part of blog "The measure, opposed by private lenders and critics of an expanding federal government, was included in a package of proposed changes to an overhaul of the U.S. healthcare system." was very interesting, thank you!


24. replica gucci ipad cases Jul 14, 2010 at 01:00

Searching your surprising blog, I consider it is of the specific experience and suitable suggestions.Believe I will acquire what exactly I aspire through your trusty ideas.Have a good day!


25. fivefingers kso Jul 26, 2010 at 23:38

fivefingers kso


26. chanel series Jul 27, 2010 at 00:43

Are you looking for chanel boots for womens?OK,come to us,you will choose the one you like best.


27. free directory list Aug 11, 2010 at 22:25

Thanks very much for the episodes and best wishse.


28. emrah eren Aug 13, 2010 at 16:47

hello thank you good information


29. authentic nike shoes Aug 19, 2010 at 20:59

Great post! Thanks for share. I really appreciate what you post. If only i could think of a plugin to actually write. I will instantly grab your rss feed to stay informed of any updates.


30. medyum Aug 20, 2010 at 12:44

Very nice sharing.thanks
www.medyumsitesi.com
medyum


31. medyum Aug 20, 2010 at 12:47

Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming


32. louis vuitton shoes Aug 26, 2010 at 21:02

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets


33. sexly Aug 29, 2010 at 23:43

tks


34. snow boots Aug 31, 2010 at 00:31

Passenger (mod_rails) is looking for someone to redo there screencast before they release.


35. levis belts Sep 01, 2010 at 21:10

I feel like I’m often looking for interesting things to read about a variety of subjects, but I manage to include your blog among my reads every day because you have interesting entries that I look forward to. Here’s hoping there’s a lot more great material coming!

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