From f16573afffc71f3265542effe459a451b6e24c17 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 10 Jan 2009 16:26:10 +0000 Subject: Add command line tools to perf guide --- railties/doc/guides/html/performance_testing.html | 103 ++++++++++++++++++--- railties/doc/guides/source/performance_testing.txt | 65 +++++++++++++ 2 files changed, 154 insertions(+), 14 deletions(-) (limited to 'railties/doc') diff --git a/railties/doc/guides/html/performance_testing.html b/railties/doc/guides/html/performance_testing.html index 54baba3a96..563485ab79 100644 --- a/railties/doc/guides/html/performance_testing.html +++ b/railties/doc/guides/html/performance_testing.html @@ -219,6 +219,16 @@ ul#navMain {
  • + Command Line Tools + +
  • +
  • Helper methods

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

    -
    -
    [lifo@null mysql]$ gcruby extconf.rb --with-mysql-config
    -[lifo@null mysql]$ make && make install
    -
    +
    +
    [lifo@null mysql]$ gcruby extconf.rb --with-mysql-config
    +[lifo@null mysql]$ make && make install

    And you’re ready to go. Don’t forget to use gcruby and gcrake aliases when running the performance tests.

    -

    2. Helper methods

    +

    2. Command Line Tools

    +
    +

    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:

    +

    2.1. benchmarker

    +

    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 [times] argument is skipped, supplied methods are run just once:

    +
    +
    +
    $ script/performance/benchmarker 'Item.first' 'Item.last'
    +

    2.2. profiler

    +

    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 with RubyProf::WALL_TIME measure mode. By default, flat output is printed to the shell.

    +
    +
    +
    $ script/performance/profiler 'Item.all' 10 graph
    +

    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:

    +
    +
    +
    $ script/performance/profiler 'Item.all' 10 graph 2> graph.txt
    +
    +

    3. Helper methods

    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.

    -

    2.1. Model

    +

    3.1. Model

    Creating project (185.3ms)

    Please refer to API docs for optional options to benchmark()

    -

    2.2. Controller

    +

    3.2. Controller

    Similarly, you could use this helper method inside controllers

    @@ -671,7 +741,7 @@ http://www.gnu.org/software/src-highlite --> Project.update_cached_projects endend -

    2.3. View

    +

    3.3. View

    And in views:

    <%= render :partial => @projects %> <% end %>
    -

    3. Request Logging

    +

    4. Request Logging

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

    @@ -704,9 +774,9 @@ http://www.gnu.org/software/src-highlite -->

    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.

    Michael Koziarski has an interesting blog post explaining the importance of using milliseconds as the metric.

    -

    4. Useful Profiling Tools

    +

    5. Useful Profiling Tools

    -

    4.1. Rails Plugins and Gems

    +

    5.1. Rails Plugins and Gems

    -

    4.2. External

    +

    5.2. External

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

    -

    5. Commercial Products

    +

    6. Commercial Products

    Rails has been lucky to have three startups dedicated to Rails specific performance tools:

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

    6. Changelog

    +

    7. Changelog

      diff --git a/railties/doc/guides/source/performance_testing.txt b/railties/doc/guides/source/performance_testing.txt index afa7f7545b..10c83e9eb2 100644 --- a/railties/doc/guides/source/performance_testing.txt +++ b/railties/doc/guides/source/performance_testing.txt @@ -363,6 +363,7 @@ Additionally, install the following gems : If installing +mysql+ fails, you can try to install it manually: +[source, shell] ---------------------------------------------------------------------------- [lifo@null mysql]$ gcruby extconf.rb --with-mysql-config [lifo@null mysql]$ make && make install @@ -370,6 +371,69 @@ If installing +mysql+ fails, you can try to install it manually: And you're ready to go. Don't forget to use +gcruby+ and +gcrake+ aliases when running the performance tests. +== Command Line Tools == + +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: + +=== benchmarker === + ++benchmarker+ is a wrapper around Ruby's http://ruby-doc.org/core/classes/Benchmark.html[Benchmark] module. + +Usage: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker [times] 'Person.expensive_way' 'Person.another_expensive_way' ... +---------------------------------------------------------------------------- + +Examples: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker 10 'Item.all' 'CouchItem.all' +---------------------------------------------------------------------------- + +If +[times]+ argument is skipped, supplied methods are run just once: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/benchmarker 'Item.first' 'Item.last' +---------------------------------------------------------------------------- + +=== profiler === + ++profiler+ is a wrapper around http://ruby-prof.rubyforge.org/[ruby-prof] gem. + +Usage: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html] +---------------------------------------------------------------------------- + +Examples: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' +---------------------------------------------------------------------------- + +This will profile +Item.all+ with +RubyProf::WALL_TIME+ measure mode. By default, flat output is printed to the shell. + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' 10 graph +---------------------------------------------------------------------------- + +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: + +[source, shell] +---------------------------------------------------------------------------- +$ script/performance/profiler 'Item.all' 10 graph 2> graph.txt +---------------------------------------------------------------------------- + == Helper methods == 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. @@ -451,6 +515,7 @@ 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] * http://github.com/josevalim/rails-footnotes/tree/master[Rails Footnotes] +* http://github.com/dsboulder/query_reviewer/tree/master[Query Reviewer] === External === -- cgit v1.2.3