Home arrow Ruby-on-Rails arrow Page 2 - Performance Optimization

Performance Optimization

If you've had a Ruby on Rails application up and running for a while, you may notice that it's not running as well as you'd like. This is when optimizing its performance can make a difference. This six-part article series will show you how. It is excerpted from chapter 13 of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
December 01, 2010
  1. · Performance Optimization
  2. · Measuring Performance

print this article

Performance Optimization - Measuring Performance
(Page 2 of 2 )

An old saying goes, “You can’t manage what you don’t measure.” You need to know what to optimize in order to optimize right things.

We have a plethora of options for measuring the performance of a Rails application. Here, we will look at what the log files can tell us, and then try out the Rails Analyzer tool set.

Checking the Log File

To use the simplest way to “profile” your application, you don’t need any extra tools. Just take a look at the development.logfile in the log directory of your application. Here is sample output of loading the show page for a book:

--------------------------------------------Processing CatalogController#show (for at 2006-09-27 23:45:30) [GET]
  Session ID: 83bd38942bba92536d89eabe192877a4
  Parameters: {"action"=>"show", "id"=>"17",
   [4;36;1mCart Load (0.000750) [0m [0;1mSELECT *
FROM carts WHERE (carts.id = 2) LIMIT 1 [0m
   [4;35;1mBook Load (0.007462) [0m [0mSELECT *
FROM books WHERE (books.id = '17') LIMIT 1 [0m
   [4;36;1mBook Columns (0.000859) [0m [0;1mSHOW
FIELDS FROM books [0m
Rendering within layouts/application Rendering catalog/show
   [4;35;1mJoin Table Columns (0.084852) [0m [0mSHOW
FIELDS FROM authors_books [0m
[4;36;1mAuthor Load (0.001258) [0m [0;1mSELECT *
FROM authors INNER JOIN authors_books ON authors.id =
authors_books.author_id WHERE (authors_books.book_id = 17 ) [0m

   [4;35;1mAuthor Columns (0.000625) [0m [0mSHOW FIELDS
FROM authors [0m
   [4;36;1mCart Columns (0.000682) [0m [0;1mSHOW FIELDS
FROM carts [0m
[4;35;1mCartItem Load (0.001169) [0m [0mSELECT * FROM
cart_items WHERE (cart_items.cart_id = 2) [0m
Rendered cart/_cart (0.08493)
Completed in 1.78054 (0 reqs/sec) | Rendering: 0.17748 (9%)
| DB: 0.09766 (5%) | 200 OK [http://localhost/catalog/show/17]

From the output, you can see the times it took to run individual SQL queries. The final lines show a summary of the whole action.

Here, we don’t see any glaring performance hogs. However, if a single database query took considerably more time than others, it would be a good starting point for optimization.

Note that only the development environment outputs this much detail in the log file.

Please check back for the second part of the series.

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials