Skip to content
This repository
Browse code

Compiling rubies installing gems

  • Loading branch information...
commit 095cafbcd7fbae3baa845b23b93c8dca93b442f8 1 parent 4ab8c08
Pratik lifo authored

Showing 1 changed file with 139 additions and 1 deletion. Show diff stats Hide diff stats

  1. +139 1 railties/doc/guides/benchmarking_and_profiling/index.txt
140 railties/doc/guides/benchmarking_and_profiling/index.txt
@@ -83,7 +83,145 @@ and http://api.rubyonrails.com/classes/ActionController/Benchmarking/ClassMethod
83 83 <% end %>
84 84 ----------------------------------------------------------------------------
85 85
86   -include::edge_rails_features.txt[]
  86 +== Performance Test Cases ==
  87 +
  88 +Rails provides a very easy to write performance test cases, which look just like the regular integration tests.
  89 +
  90 +If you have a look at +test/performance/browsing_test.rb+ in a newly created Rails application:
  91 +
  92 +[source, ruby]
  93 +----------------------------------------------------------------------------
  94 +require 'performance/test_helper'
  95 +
  96 +# Profiling results for each test method are written to tmp/performance.
  97 +class BrowsingTest < ActionController::PerformanceTest
  98 + def test_homepage
  99 + get '/'
  100 + end
  101 +end
  102 +----------------------------------------------------------------------------
  103 +
  104 +This is an automatically generated example performance test file, for testing performance of homepage('/') of the application.
  105 +
  106 +=== Modes ===
  107 +
  108 +==== Benchmarking ====
  109 +==== Profiling ====
  110 +
  111 +=== Metrics ===
  112 +
  113 +==== Process Time ====
  114 +
  115 +CPU Cycles.
  116 +
  117 +==== Memory ====
  118 +
  119 +Memory taken.
  120 +
  121 +==== Objects ====
  122 +
  123 +Objects allocated.
  124 +
  125 +==== GC Runs ====
  126 +
  127 +Number of times the Ruby GC was run.
  128 +
  129 +==== GC Time ====
  130 +
  131 +Time spent running the Ruby GC.
  132 +
  133 +=== Preparing Ruby and Ruby-prof ===
  134 +
  135 +Before we go ahead, Rails performance testing requires you to build a special Ruby binary with some super powers - GC patch for measuring GC Runs/Time. This process is very straight forward. If you've never compiled a Ruby binary before, you can follow the following steps to build a ruby binary inside your home directory:
  136 +
  137 +==== Compile ====
  138 +
  139 +[source, shell]
  140 +----------------------------------------------------------------------------
  141 +[lifo@null ~]$ mkdir rubygc
  142 +[lifo@null ~]$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p111.tar.gz
  143 +[lifo@null ~]$ tar -xzvf ruby-1.8.6-p111.tar.gz
  144 +[lifo@null ~]$ cd ruby-1.8.6-p111
  145 +[lifo@null ruby-1.8.6-p111]$ curl http://rubyforge.org/tracker/download.php/1814/7062/17676/3291/ruby186gc.patch | patch -p0
  146 +[lifo@null ruby-1.8.6-p111]$ ./configure --prefix=/Users/lifo/rubygc
  147 +[lifo@null ruby-1.8.6-p111]$ make && make install
  148 +----------------------------------------------------------------------------
  149 +
  150 +==== Prepare aliases ====
  151 +
  152 +Add the following lines in your ~/.profile for convenience:
  153 +
  154 +----------------------------------------------------------------------------
  155 +alias gcruby='/Users/lifo/rubygc/bin/ruby'
  156 +alias gcrake='/Users/lifo/rubygc/bin/rake'
  157 +alias gcgem='/Users/lifo/rubygc/bin/gem'
  158 +alias gcirb='/Users/lifo/rubygc/bin/irb'
  159 +alias gcrails='/Users/lifo/rubygc/bin/rails'
  160 +----------------------------------------------------------------------------
  161 +
  162 +==== Install rubygems and some basic gems ====
  163 +
  164 +----------------------------------------------------------------------------
  165 +[lifo@null ~]$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
  166 +[lifo@null ~]$ tar -xzvf rubygems-1.2.0.tgz
  167 +[lifo@null ~]$ cd rubygems-1.2.0
  168 +[lifo@null rubygems-1.2.0]$ gcruby setup.rb
  169 +[lifo@null rubygems-1.2.0]$ cd ~
  170 +[lifo@null ~]$ gcgem install rake
  171 +[lifo@null ~]$ gcgem install rails
  172 +----------------------------------------------------------------------------
  173 +
  174 +==== Install MySQL gem ====
  175 +
  176 +----------------------------------------------------------------------------
  177 +[lifo@null ~]$ gcgem install mysql
  178 +----------------------------------------------------------------------------
  179 +
  180 +If this fails, you can try to install it manually:
  181 +
  182 +----------------------------------------------------------------------------
  183 +[lifo@null ~]$ cd /Users/lifo/rubygc/lib/ruby/gems/1.8/gems/mysql-2.7/
  184 +[lifo@null mysql-2.7]$ gcruby extconf.rb --with-mysql-config
  185 +[lifo@null mysql-2.7]$ make && make install
  186 +----------------------------------------------------------------------------
  187 +
  188 +=== Installing Jeremy Kemper's ruby-prof ===
  189 +
  190 +We also need to install Jeremy's ruby-prof gem using our newly built ruby:
  191 +
  192 +[source, shell]
  193 +----------------------------------------------------------------------------
  194 +[lifo@null ~]$ git clone git://github.com/jeremy/ruby-prof.git
  195 +[lifo@null ~]$ cd ruby-prof/
  196 +[lifo@null ruby-prof (master)]$ gcrake gem
  197 +[lifo@null ruby-prof (master)]$ gcgem install pkg/ruby-prof-0.6.1.gem
  198 +----------------------------------------------------------------------------
  199 +
  200 +=== Generating performance test ===
  201 +
  202 +Rails provides a simple generator for creating new performance tests:
  203 +
  204 +[source, shell]
  205 +----------------------------------------------------------------------------
  206 +[User profiling_tester (master)]$ script/generate performance_test homepage
  207 +----------------------------------------------------------------------------
  208 +
  209 +This will generate +test/performance/homepage_test.rb+:
  210 +
  211 +----------------------------------------------------------------------------
  212 +require 'performance/test_helper'
  213 +
  214 +class HomepageTest < ActionController::PerformanceTest
  215 + # Replace this with your real tests.
  216 + def test_homepage
  217 + get '/'
  218 + end
  219 +end
  220 +----------------------------------------------------------------------------
  221 +
  222 +Which you can modify to suit your needs.
  223 +
  224 +=== Running tests ===
87 225
88 226 include::rubyprof.txt[]
89 227

0 comments on commit 095cafb

Please sign in to comment.
Something went wrong with that request. Please try again.