diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-01-10 16:55:42 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-01-10 16:55:42 +0000 |
commit | a5981517e6676818c3031834627e4a0763ce4fba (patch) | |
tree | 8d441bff9764a2f779ce196d53a1f903b9b8f2d5 | |
parent | 1ea5c489f392183c2b58da0f49bf9f5f2c504ad7 (diff) | |
download | rails-a5981517e6676818c3031834627e4a0763ce4fba.tar.gz rails-a5981517e6676818c3031834627e4a0763ce4fba.tar.bz2 rails-a5981517e6676818c3031834627e4a0763ce4fba.zip |
Regen html
-rw-r--r-- | railties/doc/guides/html/performance_testing.html | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/railties/doc/guides/html/performance_testing.html b/railties/doc/guides/html/performance_testing.html index 563485ab79..2e6ba0a891 100644 --- a/railties/doc/guides/html/performance_testing.html +++ b/railties/doc/guides/html/performance_testing.html @@ -214,7 +214,7 @@ ul#navMain { <li><a href="#_tuning_test_runs">Tuning Test Runs</a></li> - <li><a href="#gc">Installing GC Patched Ruby</a></li> + <li><a href="#gc">Installing GC-Patched Ruby</a></li> </ul> </li> @@ -275,17 +275,17 @@ Understand the various types of benchmarking and profiling metrics </li>
<li>
<p>
-Generate performance/benchmarking tests
+Generate performance and benchmarking tests
</p>
</li>
<li>
<p>
-Use GC patched Ruby binary to measure memory usage and object allocation
+Use a GC-patched Ruby binary to measure memory usage and object allocation
</p>
</li>
<li>
<p>
-Understand the information provided by Rails inside the log files
+Understand the benchmarking information provided by Rails inside the log files
</p>
</li>
<li>
@@ -294,12 +294,12 @@ Learn about various tools facilitating benchmarking and profiling </p>
</li>
</ul></div>
-<div class="paragraph"><p>Performance testing is an integral part of the development cycle. It is very important that you don’t make your end users wait for too long before the page is completely loaded. Ensuring a pleasant browsing experience to the end users and cutting cost of unnecessary hardwares is important for any web application.</p></div>
+<div class="paragraph"><p>Performance testing is an integral part of the development cycle. It is very important that you don’t make your end users wait for too long before the page is completely loaded. Ensuring a pleasant browsing experience for end users and cutting the cost of unnecessary hardware is important for any non-trivial web application.</p></div>
</div>
</div>
<h2 id="_performance_test_cases">1. Performance Test Cases</h2>
<div class="sectionbody">
-<div class="paragraph"><p>Rails performance tests are integration tests designed for benchmarking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.</p></div>
+<div class="paragraph"><p>Rails performance tests are a special type of integration tests, designed for benchmarking and profiling the test code. With performance tests, you can determine where your application’s memory or speed problems are coming from, and get a more in-depth picture of those problems.</p></div>
<div class="paragraph"><p>In a freshly generated Rails application, <tt>test/performance/browsing_test.rb</tt> contains an example of a performance test:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -315,7 +315,7 @@ http://www.gnu.org/software/src-highlite --> get <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>The above example is a simple performance test case for profiling a GET request to the application’s homepage.</p></div>
+<div class="paragraph"><p>This example is a simple performance test case for profiling a GET request to the application’s homepage.</p></div>
<h3 id="_generating_performance_tests">1.1. Generating performance tests</h3>
<div class="paragraph"><p>Rails provides a generator called <tt>performance_test</tt> for creating new performance tests:</p></div>
<div class="listingblock">
@@ -324,7 +324,7 @@ by Lorenzo Bettini http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>script/generate performance_test homepage</tt></pre></div></div>
-<div class="paragraph"><p>This generates <tt>homepage_test.rb</tt> inside <tt>test/performance</tt> directory:</p></div>
+<div class="paragraph"><p>This generates <tt>homepage_test.rb</tt> in the <tt>test/performance</tt> directory:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -381,7 +381,7 @@ map<span style="color: #990000">.</span>resources <span style="color: #990000">: <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 a 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>Because performance tests are a special kind of integration test, you can use the <tt>get</tt> and <tt>post</tt> methods in them.</p></div>
<div class="paragraph"><p>Here’s the performance test for <tt>HomeController#dashboard</tt> and <tt>PostsController#create</tt>:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -393,7 +393,7 @@ http://www.gnu.org/software/src-highlite --> <span style="font-weight: bold"><span style="color: #0000FF">class</span></span> PostPerformanceTest <span style="color: #990000"><</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>
+ <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>
@@ -405,9 +405,9 @@ http://www.gnu.org/software/src-highlite --> post <span style="color: #FF0000">'/posts'</span><span style="color: #990000">,</span> <span style="color: #990000">:</span>post <span style="color: #990000">=></span> <span style="color: #FF0000">{</span> <span style="color: #990000">:</span>body <span style="color: #990000">=></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>
+<div class="paragraph"><p>You can find more details about the <tt>get</tt> and <tt>post</tt> methods in the <a href="../testing_rails_applications.html#mgunderloy">Testing Rails Applications</a> guide.</p></div>
<h4 id="_model_example">1.2.2. Model Example</h4>
-<div class="paragraph"><p>Even though the performance tests are integration tests and hence closer to request/response cycle by nature, it doesn’t prevent us from performance testing pure model code.</p></div>
+<div class="paragraph"><p>Even though the performance tests are integration tests and hence closer to the request/response cycle by nature, you can still performance test pure model code.</p></div>
<div class="paragraph"><p>Performance test for <tt>Post</tt> model:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -430,7 +430,7 @@ http://www.gnu.org/software/src-highlite --> <h3 id="_modes">1.3. Modes</h3>
<div class="paragraph"><p>Performance tests can be run in two modes : Benchmarking and Profiling.</p></div>
<h4 id="_benchmarking">1.3.1. Benchmarking</h4>
-<div class="paragraph"><p>Benchmarking helps find out how fast is a performance test. Each test case is run <tt>4 times</tt> in benchmarking mode.</p></div>
+<div class="paragraph"><p>Benchmarking helps find out how fast each performance test runs. Each test case is run <tt>4 times</tt> in benchmarking mode.</p></div>
<div class="paragraph"><p>To run performance tests in benchmarking mode:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -439,7 +439,7 @@ 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.3.2. Profiling</h4>
-<div class="paragraph"><p>Profiling helps you introspect into a performance test and provide an in-depth picture of the slow and memory hungry parts. Each Test case is run <tt>1 time</tt> in profiling mode.</p></div>
+<div class="paragraph"><p>Profiling helps you see the details of a performance test and provide an in-depth picture of the slow and memory hungry parts. Each test case is run <tt>1 time</tt> in profiling mode.</p></div>
<div class="paragraph"><p>To run performance tests in profiling mode:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -450,25 +450,25 @@ http://www.gnu.org/software/src-highlite --> <h3 id="_metrics">1.4. Metrics</h3>
<div class="paragraph"><p>Benchmarking and profiling run performance tests in various modes described below.</p></div>
<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>Wall time 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.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>Process time 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.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>
+<div class="paragraph"><p>Memory 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.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>
+<div class="paragraph"><p>Objects 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.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>
+<div class="paragraph"><p>GC Runs 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.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>
+<div class="paragraph"><p>GC Time 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.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>
+<div class="paragraph"><p>Performance tests generate different outputs inside <tt>tmp/performance</tt> directory depending on their mode and metric.</p></div>
<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>
@@ -513,7 +513,7 @@ BrowsingTest#test_homepage_wall_time.csv </p>
</li>
</ul></div>
-<div class="paragraph"><p>As the results are appended to these files each time the performance tests are run in benchmarking mode, it enables you to collect data over a period of time which can be very helpful with various performance analysis.</p></div>
+<div class="paragraph"><p>As the results are appended to these files each time the performance tests are run in benchmarking mode, you can collect data over a period of time. This can be very helpful in analyzing the effects of code changes.</p></div>
<div class="paragraph"><p>Sample output of <tt>BrowsingTest#test_homepage_wall_time.csv</tt>:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
@@ -532,6 +532,7 @@ http://www.gnu.org/software/src-highlite --> <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.5.2. Profiling</h4>
+<div class="paragraph"><p>In profiling mode, you can choose from four types of output.</p></div>
<h5 id="_command_line_2">Command line</h5>
<div class="paragraph"><p>This is a very basic form of output in profiling mode:</p></div>
<div class="listingblock">
@@ -556,12 +557,12 @@ http://www.gnu.org/software/src-highlite --> <td class="icon">
<img src="./images/icons/caution.png" alt="Caution" />
</td>
-<td class="content">That’s a lie. But not for long.</td>
+<td class="content">Performance test configurability is not yet enabled in Rails. But it will be soon.</td>
</tr></table>
</div>
-<h3 id="gc">1.7. Installing GC Patched Ruby</h3>
+<h3 id="gc">1.7. Installing GC-Patched Ruby</h3>
<div class="paragraph"><p>To get the best from Rails performance tests, you need to build a special Ruby binary with some super powers - <a href="http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch">GC patch</a> for measuring GC Runs/Time and memory/object allocation.</p></div>
-<div class="paragraph"><p>The process is fairly straight forward. If you’ve never compiled a Ruby binary before, follow the following steps to build a ruby binary inside your home directory:</p></div>
+<div class="paragraph"><p>The process is fairly straight forward. If you’ve never compiled a Ruby binary before, follow these steps to build a ruby binary inside your home directory:</p></div>
<h4 id="_installation">1.7.1. Installation</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.7.2. Download and Extract</h4>
@@ -642,7 +643,7 @@ http://www.gnu.org/software/src-highlite --> </div>
<h2 id="_command_line_tools">2. Command Line Tools</h2>
<div class="sectionbody">
-<div class="paragraph"><p>Writing performance test cases could be an overkill when you are looking for one time tests. Rails ships with two command line tools for allowing such quick and dirty performance testing:</p></div>
+<div class="paragraph"><p>Writing performance test cases could be an overkill when you are looking for one time tests. Rails ships with two command line tools that enable quick and dirty performance testing:</p></div>
<h3 id="_benchmarker">2.1. benchmarker</h3>
<div class="paragraph"><p><tt>benchmarker</tt> is a wrapper around Ruby’s <a href="http://ruby-doc.org/core/classes/Benchmark.html">Benchmark</a> module.</p></div>
<div class="paragraph"><p>Usage:</p></div>
@@ -659,7 +660,7 @@ by Lorenzo Bettini http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ script/performance/benchmarker <span style="color: #993399">10</span> <span style="color: #FF0000">'Item.all'</span> <span style="color: #FF0000">'CouchItem.all'</span></tt></pre></div></div>
-<div class="paragraph"><p>If <tt>[times]</tt> argument is skipped, supplied methods are run just once:</p></div>
+<div class="paragraph"><p>If the <tt>[times]</tt> argument is omitted, supplied methods are run just once:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -682,7 +683,7 @@ by Lorenzo Bettini http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>$ script/performance/profiler <span style="color: #FF0000">'Item.all'</span></tt></pre></div></div>
-<div class="paragraph"><p>This will profile <tt>Item.all</tt> with <tt>RubyProf::WALL_TIME</tt> measure mode. By default, flat output is printed to the shell.</p></div>
+<div class="paragraph"><p>This will profile <tt>Item.all</tt> in <tt>RubyProf::WALL_TIME</tt> measure mode. By default, it prints flat output to the shell.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 2.9
by Lorenzo Bettini
@@ -712,14 +713,14 @@ http://www.gnu.org/software/src-highlite --> project<span style="color: #990000">.</span>create_manager<span style="color: #990000">(</span><span style="color: #FF0000">"name"</span> <span style="color: #990000">=></span> <span style="color: #FF0000">"David"</span><span style="color: #990000">)</span>
project<span style="color: #990000">.</span>milestones <span style="color: #990000"><<</span> Milestone<span style="color: #990000">.</span>find<span style="color: #990000">(:</span>all<span style="color: #990000">)</span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
-<div class="paragraph"><p>This benchmarks the code enclosed in <tt>Project.benchmark("Creating project") do..end</tt> block and prints the result to the log file:</p></div>
+<div class="paragraph"><p>This benchmarks the code enclosed in the <tt>Project.benchmark("Creating project") do..end</tt> block and prints the result to the log file:</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>Creating project <span style="color: #990000">(</span><span style="color: #993399">185</span><span style="color: #990000">.</span>3ms<span style="color: #990000">)</span></tt></pre></div></div>
-<div class="paragraph"><p>Please refer to <a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336">API docs</a> for optional options to <tt>benchmark()</tt></p></div>
+<div class="paragraph"><p>Please refer to the <a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001336">API docs</a> for additional options to <tt>benchmark()</tt></p></div>
<h3 id="_controller">3.2. Controller</h3>
<div class="paragraph"><p>Similarly, you could use this helper method inside <a href="http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethods.html#M000715">controllers</a></p></div>
<div class="admonitionblock">
@@ -771,7 +772,7 @@ by Lorenzo Bettini http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>Completed <span style="font-weight: bold"><span style="color: #0000FF">in</span></span> 5ms <span style="color: #990000">(</span>View<span style="color: #990000">:</span> <span style="color: #993399">2</span><span style="color: #990000">,</span> DB<span style="color: #990000">:</span> <span style="color: #993399">0</span><span style="color: #990000">)</span> <span style="color: #990000">|</span> <span style="color: #993399">200</span> OK <span style="color: #990000">[</span>http<span style="color: #990000">:</span><span style="color: #FF6600">//0.0.0.0/</span>items<span style="color: #990000">]</span></tt></pre></div></div>
-<div class="paragraph"><p>This data is fairly straight forward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It’s safe to assume that the remaining 3 ms were spent inside the controller.</p></div>
+<div class="paragraph"><p>This data is fairly straightforward to understand. Rails uses millisecond(ms) as the metric to measures the time taken. The complete request spent 5 ms inside Rails, out of which 2 ms were spent rendering views and none was spent communication with the database. It’s safe to assume that the remaining 3 ms were spent inside the controller.</p></div>
<div class="paragraph"><p>Michael Koziarski has an <a href="http://www.therailsway.com/2009/1/6/requests-per-second">interesting blog post</a> explaining the importance of using milliseconds as the metric.</p></div>
</div>
<h2 id="_useful_profiling_tools">5. Useful Profiling Tools</h2>
|