From 4dd764207cce57ae4f592b383620b2f49fe2c727 Mon Sep 17 00:00:00 2001 From: Karel Minarik Date: Sat, 17 Jan 2009 19:12:13 +0100 Subject: Clarifications and additions to the introduction part of Internationalization (I18n) guide --- railties/doc/guides/html/performance_testing.html | 58 +++++++++++------------ 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'railties/doc/guides/html/performance_testing.html') diff --git a/railties/doc/guides/html/performance_testing.html b/railties/doc/guides/html/performance_testing.html index 858076008d..95bfd5f980 100644 --- a/railties/doc/guides/html/performance_testing.html +++ b/railties/doc/guides/html/performance_testing.html @@ -138,7 +138,7 @@ Learn about various tools facilitating benchmarking and profiling

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.

In a freshly generated Rails application, test/performance/browsing_test.rb contains an example of a performance test:

-
@@ -155,14 +155,14 @@ http://www.gnu.org/software/src-highlite -->

1.1. Generating performance tests

Rails provides a generator called performance_test for creating new performance tests:

-
script/generate performance_test homepage

This generates homepage_test.rb in the test/performance directory:

-
@@ -178,7 +178,7 @@ http://www.gnu.org/software/src-highlite -->

1.2. Examples

Let’s assume your application has the following controller and model:

-
@@ -220,7 +220,7 @@ map.resources :

Because performance tests are a special kind of integration test, you can use the get and post methods in them.

Here’s the performance test for HomeController#dashboard and PostsController#create:

-
@@ -246,7 +246,7 @@ http://www.gnu.org/software/src-highlite -->

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.

Performance test for Post model:

-
@@ -269,7 +269,7 @@ http://www.gnu.org/software/src-highlite -->

Benchmarking helps find out how fast each performance test runs. Each test case is run 4 times in benchmarking mode.

To run performance tests in benchmarking mode:

-
@@ -278,7 +278,7 @@ http://www.gnu.org/software/src-highlite -->

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 1 time in profiling mode.

To run performance tests in profiling mode:

-
@@ -310,7 +310,7 @@ http://www.gnu.org/software/src-highlite -->
Command line

This is the primary form of output in benchmarking mode. Example :

-
@@ -352,7 +352,7 @@ BrowsingTest#test_homepage_wall_time.csv

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.

Sample output of BrowsingTest#test_homepage_wall_time.csv:

-
@@ -372,7 +372,7 @@ http://www.gnu.org/software/src-highlite -->
Command line

This is a very basic form of output in profiling mode:

-
@@ -399,7 +399,7 @@ http://www.gnu.org/software/src-highlite -->

1.7. Performance Test Environment

Performance tests are run in the development environment. But running performance tests will set the following configuration parameters:

-
@@ -414,7 +414,7 @@ Rails.logger.

Compile Ruby and apply this GC Patch:

1.8.2. Download and Extract

-
@@ -424,7 +424,7 @@ http://www.gnu.org/software/src-highlite --> [lifo@null ~]$ cd <ruby-version>

1.8.3. Apply the patch

-
@@ -432,7 +432,7 @@ http://www.gnu.org/software/src-highlite -->

1.8.4. Configure and Install

The following will install ruby in your home directory’s /rubygc directory. Make sure to replace <homedir> with a full patch to your actual home directory.

-
@@ -480,7 +480,7 @@ alias gcrails='~/rubygc/bin/rails'

If installing mysql fails, you can try to install it manually:

-
@@ -495,21 +495,21 @@ http://www.gnu.org/software/src-highlite -->

benchmarker is a wrapper around Ruby’s Benchmark module.

Usage:

-
$ script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ...

Examples:

-
$ script/performance/benchmarker 10 'Item.all' 'CouchItem.all'

If the [times] argument is omitted, supplied methods are run just once:

-
@@ -518,21 +518,21 @@ http://www.gnu.org/software/src-highlite -->

profiler is a wrapper around ruby-prof gem.

Usage:

-
$ script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]

Examples:

-
$ script/performance/profiler 'Item.all'

This will profile Item.all in RubyProf::WALL_TIME measure mode. By default, it prints flat output to the shell.

-
@@ -540,7 +540,7 @@ http://www.gnu.org/software/src-highlite -->

This will profile 10.times { Item.all } with RubyProf::WALL_TIME measure mode and print graph output to the shell.

If you want to store the output in a file:

-
@@ -551,7 +551,7 @@ http://www.gnu.org/software/src-highlite -->

Rails provides various helper methods inside Active Record, Action Controller and Action View to measure the time taken by a given piece of code. The method is called benchmark() in all the three components.

3.1. Model

-
@@ -562,7 +562,7 @@ http://www.gnu.org/software/src-highlite --> end

This benchmarks the code enclosed in the Project.benchmark("Creating project") do..end block and prints the result to the log file:

-
@@ -579,7 +579,7 @@ http://www.gnu.org/software/src-highlite -->
-
@@ -592,7 +592,7 @@ http://www.gnu.org/software/src-highlite -->

3.3. View

And in views:

-
@@ -604,7 +604,7 @@ http://www.gnu.org/software/src-highlite -->

Rails log files contain very useful information about the time taken to serve each request. Here’s a typical log file entry:

-
@@ -614,7 +614,7 @@ Rendering items/index Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]

For this section, we’re only interested in the last line:

-
-- cgit v1.2.3