aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/doc/guides/html/performance_testing.html164
-rw-r--r--railties/doc/guides/source/performance_testing.txt99
2 files changed, 231 insertions, 32 deletions
diff --git a/railties/doc/guides/html/performance_testing.html b/railties/doc/guides/html/performance_testing.html
index 4a4d15eac6..dbbd52fa2b 100644
--- a/railties/doc/guides/html/performance_testing.html
+++ b/railties/doc/guides/html/performance_testing.html
@@ -2,7 +2,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Performance testing Rails Applications</title>
+ <title>Performance Testing Rails Applications</title>
<!--[if lt IE 8]>
<script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script>
<![endif]-->
@@ -204,6 +204,8 @@ ul#navMain {
<li><a href="#_generating_performance_tests">Generating performance tests</a></li>
+ <li><a href="#_examples">Examples</a></li>
+
<li><a href="#_modes">Modes</a></li>
<li><a href="#_metrics">Metrics</a></li>
@@ -233,7 +235,7 @@ ul#navMain {
<a href="#_other_profiling_tools">Other Profiling Tools</a>
</li>
<li>
- <a href="#_commercial_products_dedicated_to_rails_perfomance">Commercial products dedicated to Rails Perfomance</a>
+ <a href="#_commercial_products">Commercial products</a>
</li>
<li>
<a href="#_changelog">Changelog</a>
@@ -242,7 +244,7 @@ ul#navMain {
</div>
<div id="content">
- <h1>Performance testing Rails Applications</h1>
+ <h1>Performance Testing Rails Applications</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph"><p>This guide covers the various ways of performance testing a Ruby on Rails application. By referring to this guide, you will be able to:</p></div>
@@ -319,9 +321,96 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
<div class="paragraph"><p>Which you can modify to suit your needs.</p></div>
-<h3 id="_modes">1.2. Modes</h3>
+<h3 id="_examples">1.2. Examples</h3>
+<div class="paragraph"><p>Let&#8217;s assume your application have the following controller and model:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-style: italic"><span style="color: #9A1900"># routes.rb</span></span>
+map<span style="color: #990000">.</span>root <span style="color: #990000">:</span>controller <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'home'</span>
+map<span style="color: #990000">.</span>resources <span style="color: #990000">:</span>posts
+
+<span style="font-style: italic"><span style="color: #9A1900"># home_controller.rb</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> HomeController <span style="color: #990000">&lt;</span> ApplicationController
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> dashboard
+ <span style="color: #009900">@users</span> <span style="color: #990000">=</span> User<span style="color: #990000">.</span>last_ten<span style="color: #990000">(:</span><span style="font-weight: bold"><span style="color: #0000FF">include</span></span> <span style="color: #990000">=&gt;</span> <span style="color: #990000">:</span>avatars<span style="color: #990000">)</span>
+ <span style="color: #009900">@posts</span> <span style="color: #990000">=</span> Post<span style="color: #990000">.</span>all_today
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+<span style="font-style: italic"><span style="color: #9A1900"># posts_controller.rb</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> PostsController <span style="color: #990000">&lt;</span> ApplicationController
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> create
+ <span style="color: #009900">@post</span> <span style="color: #990000">=</span> Post<span style="color: #990000">.</span>create<span style="color: #990000">(</span>params<span style="color: #990000">[:</span>post<span style="color: #990000">])</span>
+ redirect_to<span style="color: #990000">(</span><span style="color: #009900">@post</span><span style="color: #990000">)</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+<span style="font-style: italic"><span style="color: #9A1900"># post.rb</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Post <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
+ before_save <span style="color: #990000">:</span>recalculate_costly_stats
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> slow_method
+ <span style="font-style: italic"><span style="color: #9A1900"># I fire gallzilion queries sleeping all around</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+ private
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> recalculate_costly_stats
+ <span style="font-style: italic"><span style="color: #9A1900"># CPU heavy calculations</span></span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<h4 id="_controller_example">1.2.1. Controller Example</h4>
+<div class="paragraph"><p>Performance tests are special kind of integration tests. This allows you to use <tt>get</tt> and <tt>post</tt> methods inside the performance tests.</p></div>
+<div class="paragraph"><p>Performance tests for the controller code above can be something like:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'test_helper'</span>
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'performance_test_help'</span>
+
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> PostPerformanceTest <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>PerformanceTest
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> setup
+ <span style="font-style: italic"><span style="color: #9A1900"># Application requires logged in user</span></span>
+ login_as<span style="color: #990000">(:</span>lifo<span style="color: #990000">)</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_homepage
+ get <span style="color: #FF0000">'/dashboard'</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_creating_new_post
+ post <span style="color: #FF0000">'/posts'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>post <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">{</span> <span style="color: #990000">:</span>body <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'lifo is fooling you'</span> <span style="color: #FF0000">}</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>You can find more details about <tt>get</tt> and <tt>post</tt> methods in API documentation of integration testing.</p></div>
+<h4 id="_model_example">1.2.2. Model Example</h4>
+<div class="paragraph"><p>Even though performance tests are integration tests and hence closer to request/response cycle by nature, it doesn&#8217;t prevent us from testing pure model code inside. Performance test for <tt>Post</tt> model above can be somewhat like:</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'test_helper'</span>
+<span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'performance_test_help'</span>
+
+<span style="font-weight: bold"><span style="color: #0000FF">class</span></span> PostModelTest <span style="color: #990000">&lt;</span> ActionController<span style="color: #990000">::</span>PerformanceTest
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_creation
+ Post<span style="color: #990000">.</span>create <span style="color: #990000">:</span>body <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'still fooling you'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>cost <span style="color: #990000">=&gt;</span> <span style="color: #FF0000">'100'</span>
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+
+ <span style="font-weight: bold"><span style="color: #0000FF">def</span></span> test_slow_method
+ <span style="font-style: italic"><span style="color: #9A1900"># Using posts(:awesome) fixture</span></span>
+ posts<span style="color: #990000">(:</span>awesome<span style="color: #990000">).</span>slow_method
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<h3 id="_modes">1.3. Modes</h3>
<div class="paragraph"><p>Performance test cases can be run in two modes : Benchmarking and Profling.</p></div>
-<h4 id="_benchmarking">1.2.1. Benchmarking</h4>
+<h4 id="_benchmarking">1.3.1. Benchmarking</h4>
<div class="paragraph"><p>Benchmarking helps you find out how fast are your test cases. Each Test case is run <tt>4 times</tt> in this mode. To run performance tests in benchmarking mode:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -329,7 +418,7 @@ by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ rake <span style="font-weight: bold"><span style="color: #0000FF">test</span></span><span style="color: #990000">:</span>benchmark</tt></pre></div></div>
-<h4 id="_profiling">1.2.2. Profiling</h4>
+<h4 id="_profiling">1.3.2. Profiling</h4>
<div class="paragraph"><p>Profiling helps introspect into your test cases and figure out which are the slow parts. Each Test case is run <tt>1 time</tt> in this mode. To run performance tests in profiling mode:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -337,29 +426,29 @@ by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ rake <span style="font-weight: bold"><span style="color: #0000FF">test</span></span><span style="color: #990000">:</span>profile</tt></pre></div></div>
-<h3 id="_metrics">1.3. Metrics</h3>
+<h3 id="_metrics">1.4. Metrics</h3>
<div class="paragraph"><p>Benchmarking and profiling run performance test cases in various modes to help precisely figure out the where the problem lies.</p></div>
-<h4 id="_wall_time">1.3.1. Wall Time</h4>
+<h4 id="_wall_time">1.4.1. Wall Time</h4>
<div class="paragraph"><p>Measures the real world time elapsed during the test run. It is affected by any other processes concurrently running on the system.</p></div>
<div class="paragraph"><p>Mode : Benchmarking</p></div>
-<h4 id="_process_time">1.3.2. Process Time</h4>
+<h4 id="_process_time">1.4.2. Process Time</h4>
<div class="paragraph"><p>Measures the time taken by the process. It is unaffected by any other processes running concurrently on the same system. Hence, process time is likely to be constant for any given performance test, irrespective of the machine load.</p></div>
<div class="paragraph"><p>Mode : Profiling</p></div>
-<h4 id="_memory">1.3.3. Memory</h4>
+<h4 id="_memory">1.4.3. Memory</h4>
<div class="paragraph"><p>Measures the amount of memory used for the performance test case.</p></div>
<div class="paragraph"><p>Mode : Benchmarking, Profiling [<a href="#gc">Requires GC Patched Ruby</a>]</p></div>
-<h4 id="_objects">1.3.4. Objects</h4>
+<h4 id="_objects">1.4.4. Objects</h4>
<div class="paragraph"><p>Measures the number of objects allocated for the performance test case.</p></div>
<div class="paragraph"><p>Mode : Benchmarking, Profiling [<a href="#gc">Requires GC Patched Ruby</a>]</p></div>
-<h4 id="_gc_runs">1.3.5. GC Runs</h4>
+<h4 id="_gc_runs">1.4.5. GC Runs</h4>
<div class="paragraph"><p>Measures the number of times GC was invoked for the performance test case.</p></div>
<div class="paragraph"><p>Mode : Benchmarking [<a href="#gc">Requires GC Patched Ruby</a>]</p></div>
-<h4 id="_gc_time">1.3.6. GC Time</h4>
+<h4 id="_gc_time">1.4.6. GC Time</h4>
<div class="paragraph"><p>Measures the amount of time spent in GC for the performance test case.</p></div>
<div class="paragraph"><p>Mode : Benchmarking [<a href="#gc">Requires GC Patched Ruby</a>]</p></div>
-<h3 id="_understanding_the_output">1.4. Understanding the output</h3>
+<h3 id="_understanding_the_output">1.5. Understanding the output</h3>
<div class="paragraph"><p>Performance tests generate different outputs inside <tt>tmp/performance</tt> directory based on the mode it is run in and the metric.</p></div>
-<h4 id="_benchmarking_2">1.4.1. Benchmarking</h4>
+<h4 id="_benchmarking_2">1.5.1. Benchmarking</h4>
<div class="paragraph"><p>In benchmarking mode, performance tests generate two types of outputs :</p></div>
<h5 id="_command_line">Command line</h5>
<div class="paragraph"><p>This is the primary form of output in benchmarking mode. Example :</p></div>
@@ -421,7 +510,7 @@ http://www.gnu.org/software/src-highlite -->
<span style="color: #993399">0.00740450000000004</span><span style="color: #990000">,</span><span style="color: #993399">2009</span>-<span style="color: #993399">01</span>-09T03<span style="color: #990000">:</span><span style="color: #993399">54</span><span style="color: #990000">:</span>47Z<span style="color: #990000">,,</span><span style="color: #993399">2.3</span><span style="color: #990000">.</span><span style="color: #993399">0</span><span style="color: #990000">.</span>master<span style="color: #990000">.</span><span style="color: #993399">859e150</span><span style="color: #990000">,</span>ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6.110</span><span style="color: #990000">,</span>i686-darwin<span style="color: #993399">9.0</span><span style="color: #990000">.</span><span style="color: #993399">0</span>
<span style="color: #993399">0.00603150000000008</span><span style="color: #990000">,</span><span style="color: #993399">2009</span>-<span style="color: #993399">01</span>-09T03<span style="color: #990000">:</span><span style="color: #993399">54</span><span style="color: #990000">:</span>57Z<span style="color: #990000">,,</span><span style="color: #993399">2.3</span><span style="color: #990000">.</span><span style="color: #993399">0</span><span style="color: #990000">.</span>master<span style="color: #990000">.</span><span style="color: #993399">859e150</span><span style="color: #990000">,</span>ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6.111</span><span style="color: #990000">,</span>i686-darwin<span style="color: #993399">9.1</span><span style="color: #990000">.</span><span style="color: #993399">0</span>
<span style="color: #993399">0.00771250000000012</span><span style="color: #990000">,</span><span style="color: #993399">2009</span>-<span style="color: #993399">01</span>-09T15<span style="color: #990000">:</span><span style="color: #993399">46</span><span style="color: #990000">:</span>03Z<span style="color: #990000">,,</span><span style="color: #993399">2.3</span><span style="color: #990000">.</span><span style="color: #993399">0</span><span style="color: #990000">.</span>master<span style="color: #990000">.</span><span style="color: #993399">859e150</span><span style="color: #990000">,</span>ruby-<span style="color: #993399">1.8</span><span style="color: #990000">.</span><span style="color: #993399">6.110</span><span style="color: #990000">,</span>i686-darwin<span style="color: #993399">9.0</span><span style="color: #990000">.</span><span style="color: #993399">0</span></tt></pre></div></div>
-<h4 id="_profiling_2">1.4.2. Profiling</h4>
+<h4 id="_profiling_2">1.5.2. Profiling</h4>
<h5 id="_command_line_2">Command line</h5>
<div class="paragraph"><p>This is the very basic form of output in profiling mode. Example :</p></div>
<div class="listingblock">
@@ -439,10 +528,11 @@ http://www.gnu.org/software/src-highlite -->
<div class="paragraph"><p>Graph output shows how long each method takes to run, which methods call it and which methods it calls. <a href="http://ruby-prof.rubyforge.org/files/examples/graph_txt.html">Check ruby prof documentation for a better explaination</a>.</p></div>
<h5 id="_tree">Tree</h5>
<div class="paragraph"><p>Tree output is profiling information in calltree format for use by kcachegrind and similar tools.</p></div>
-<h3 id="gc">1.5. Installing GC Patched Ruby</h3>
+<h3 id="gc">1.6. Installing GC Patched Ruby</h3>
<div class="paragraph"><p>To get the best from Rails performance test cases, you need to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time and memory/object allocation profiling. This process is very straight forward. If you&#8217;ve never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory:</p></div>
-<h4 id="_compile">1.5.1. Compile</h4>
+<h4 id="_instllation">1.6.1. Instllation</h4>
<div class="paragraph"><p>Compile Ruby and apply this <a href="http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch">GC Patch</a>:</p></div>
+<h4 id="_download_and_extract">1.6.2. Download and Extract</h4>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -451,21 +541,34 @@ http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ mkdir rubygc
<span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ wget <span style="color: #990000">&lt;</span>download the latest stable ruby from ftp<span style="color: #990000">:</span>//ftp<span style="color: #990000">.</span>ruby-lang<span style="color: #990000">.</span>org/pub/ruby<span style="color: #990000">&gt;</span>
<span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ tar -xzvf <span style="color: #990000">&lt;</span>ruby-version<span style="color: #990000">.</span>tar<span style="color: #990000">.</span>gz<span style="color: #990000">&gt;</span>
-<span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ cd <span style="color: #990000">&lt;</span>ruby-version<span style="color: #990000">&gt;</span>
-<span style="color: #990000">[</span>lifo@null ruby-version<span style="color: #990000">]</span>$ curl http<span style="color: #990000">:</span>//rubyforge<span style="color: #990000">.</span>org/tracker/download<span style="color: #990000">.</span>php<span style="color: #990000">/</span><span style="color: #993399">1814</span><span style="color: #990000">/</span><span style="color: #993399">7062</span><span style="color: #990000">/</span><span style="color: #993399">17676</span><span style="color: #990000">/</span><span style="color: #993399">3291</span>/ruby186gc<span style="color: #990000">.</span>patch <span style="color: #990000">|</span> patch -p<span style="color: #993399">0</span>
-<span style="color: #990000">[</span>lifo@null ruby-version<span style="color: #990000">]</span>$ <span style="color: #990000">.</span>/configure --prefix<span style="color: #990000">=</span>/Users/lifo/rubygc
+<span style="color: #990000">[</span>lifo@null <span style="color: #990000">~]</span>$ cd <span style="color: #990000">&lt;</span>ruby-version<span style="color: #990000">&gt;</span></tt></pre></div></div>
+<h4 id="_apply_the_patch">1.6.3. Apply the patch</h4>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #990000">[</span>lifo@null ruby-version<span style="color: #990000">]</span>$ curl http<span style="color: #990000">:</span>//rubyforge<span style="color: #990000">.</span>org/tracker/download<span style="color: #990000">.</span>php<span style="color: #990000">/</span><span style="color: #993399">1814</span><span style="color: #990000">/</span><span style="color: #993399">7062</span><span style="color: #990000">/</span><span style="color: #993399">17676</span><span style="color: #990000">/</span><span style="color: #993399">3291</span>/ruby186gc<span style="color: #990000">.</span>patch <span style="color: #990000">|</span> patch -p<span style="color: #993399">0</span></tt></pre></div></div>
+<h4 id="_configure_and_install">1.6.4. Configure and Install</h4>
+<div class="paragraph"><p>The following will install ruby in your home directory&#8217;s <tt>/rubygc</tt> directory. Make sure to replace <tt>&lt;homedir&gt;</tt> with a full patch to your actual home directory.</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="color: #990000">[</span>lifo@null ruby-version<span style="color: #990000">]</span>$ <span style="color: #990000">.</span>/configure --prefix<span style="color: #990000">=/&lt;</span>homedir<span style="color: #990000">&gt;</span>/rubygc
<span style="color: #990000">[</span>lifo@null ruby-version<span style="color: #990000">]</span>$ make <span style="color: #990000">&amp;&amp;</span> make install</tt></pre></div></div>
-<h4 id="_prepare_aliases">1.5.2. Prepare aliases</h4>
-<div class="paragraph"><p>Add the following lines in your ~/.profile for convenience:</p></div>
+<h4 id="_prepare_aliases">1.6.5. Prepare aliases</h4>
+<div class="paragraph"><p>For convenience, add the following lines in your ~/.profile after replacing &lt;username&gt; with your :</p></div>
<div class="listingblock">
<div class="content">
-<pre><tt>alias gcruby='/Users/lifo/rubygc/bin/ruby'
-alias gcrake='/Users/lifo/rubygc/bin/rake'
-alias gcgem='/Users/lifo/rubygc/bin/gem'
-alias gcirb='/Users/lifo/rubygc/bin/irb'
-alias gcrails='/Users/lifo/rubygc/bin/rails'</tt></pre>
+<pre><tt>alias gcruby='~/rubygc/bin/ruby'
+alias gcrake='~/rubygc/bin/rake'
+alias gcgem='~/rubygc/bin/gem'
+alias gcirb='~/rubygc/bin/irb'
+alias gcrails='~/rubygc/bin/rails'</tt></pre>
</div></div>
-<h4 id="_install_rubygems_and_some_basic_gems">1.5.3. Install rubygems and some basic gems</h4>
+<h4 id="_install_rubygems_and_some_basic_gems">1.6.6. Install rubygems and some basic gems</h4>
<div class="paragraph"><p>Download <a href="http://rubyforge.org/projects/rubygems">Rubygems</a> and install it from source. Rubygem&#8217;s README file should have necessary installation instructions.</p></div>
<div class="paragraph"><p>Additionally, installa the following gems :</p></div>
<div class="ulist"><ul>
@@ -591,8 +694,9 @@ http://www.gnu.org/software/src-highlite -->
</li>
</ul></div>
</div>
-<h2 id="_commercial_products_dedicated_to_rails_perfomance">5. Commercial products dedicated to Rails Perfomance</h2>
+<h2 id="_commercial_products">5. Commercial products</h2>
<div class="sectionbody">
+<div class="paragraph"><p>Rails has been lucky to have three startups dedicated to Rails specific performance tools:</p></div>
<div class="ulist"><ul>
<li>
<p>
diff --git a/railties/doc/guides/source/performance_testing.txt b/railties/doc/guides/source/performance_testing.txt
index f42b3686b7..e58927b758 100644
--- a/railties/doc/guides/source/performance_testing.txt
+++ b/railties/doc/guides/source/performance_testing.txt
@@ -1,4 +1,4 @@
-Performance testing Rails Applications
+Performance Testing Rails Applications
======================================
This guide covers the various ways of performance testing a Ruby on Rails application. By referring to this guide, you will be able to:
@@ -58,6 +58,98 @@ end
Which you can modify to suit your needs.
+=== Examples ===
+
+Let's assume your application have the following controller and model:
+
+[source, ruby]
+----------------------------------------------------------------------------
+# routes.rb
+map.root :controller => 'home'
+map.resources :posts
+
+# home_controller.rb
+class HomeController < ApplicationController
+ def dashboard
+ @users = User.last_ten(:include => :avatars)
+ @posts = Post.all_today
+ end
+end
+
+# posts_controller.rb
+class PostsController < ApplicationController
+ def create
+ @post = Post.create(params[:post])
+ redirect_to(@post)
+ end
+end
+
+# post.rb
+class Post < ActiveRecord::Base
+ before_save :recalculate_costly_stats
+
+ def slow_method
+ # I fire gallzilion queries sleeping all around
+ end
+
+ private
+
+ def recalculate_costly_stats
+ # CPU heavy calculations
+ end
+end
+----------------------------------------------------------------------------
+
+==== Controller Example ====
+
+Performance tests are special kind of integration tests. This allows you to use +get+ and +post+ methods inside the performance tests.
+
+Performance tests for the controller code above can be something like:
+
+[source, ruby]
+----------------------------------------------------------------------------
+require 'test_helper'
+require 'performance_test_help'
+
+class PostPerformanceTest < ActionController::PerformanceTest
+ def setup
+ # Application requires logged in user
+ login_as(:lifo)
+ end
+
+ def test_homepage
+ get '/dashboard'
+ end
+
+ def test_creating_new_post
+ post '/posts', :post => { :body => 'lifo is fooling you' }
+ end
+end
+----------------------------------------------------------------------------
+
+You can find more details about +get+ and +post+ methods in API documentation of integration testing.
+
+==== Model Example ====
+
+Even though performance tests are integration tests and hence closer to request/response cycle by nature, it doesn't prevent us from testing pure model code inside. Performance test for +Post+ model above can be somewhat like:
+
+[source, ruby]
+----------------------------------------------------------------------------
+require 'test_helper'
+require 'performance_test_help'
+
+class PostModelTest < ActionController::PerformanceTest
+ def test_creation
+ Post.create :body => 'still fooling you', :cost => '100'
+ end
+
+ def test_slow_method
+ # Using posts(:awesome) fixture
+ posts(:awesome).slow_method
+ end
+end
+----------------------------------------------------------------------------
+
=== Modes ===
Performance test cases can be run in two modes : Benchmarking and Profling.
@@ -344,7 +436,10 @@ Michael Koziarski has an http://www.therailsway.com/2009/1/6/requests-per-second
* http://rails-analyzer.rubyforge.org/[Rails Analyzer]
* http://www.flyingmachinestudios.com/projects/[Palmist]
-== Commercial products dedicated to Rails Perfomance ==
+== Commercial products ==
+
+Rails has been lucky to have three startups dedicated to Rails specific performance tools:
+
* http://www.newrelic.com[New Relic]
* http://www.fiveruns.com[Fiveruns]
* http://scoutapp.com[Scout]