Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

A guide to performance testing in rails

Notifications You must be signed in to change notification settings

ngauthier/performance-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 

Repository files navigation

Get the code

git clone git:/ngauthier/performance-testing.git

Try it yourself

Initial Project

Checkout the branch

git checkout origin/initial
cd sample-project
# you may need to gem install geminstaller
sudo geminstaller

Edit your database.yml to suit your machine.

Initialize the server

RAILS_ENV=development rake db:drop db:create db:schema:load db:stories
rm log/development.log
RAILS_ENV=development ruby script/server

Browse to page. Hit refresh a few times. Click on new and edit.

Check the server speed

slow-actions log/development.log --actions

And check the speed of the tests

rm log/test.log
RAILS_ENV=test rake db:drop db:create db:schema:load db:stories test
slow-actions log/test.log --actions

Simulate production for a week

Got an email from a user: “lol ur site sux takes liek 5mins to load hahaha n00b”

Pull from production:

RAILS_ENV=development rake data:load
RAILS_ENV=development ruby script/server

Browse to index

# usually we would pull from the production log
slow-actions log/development.log --actions

OK, we have a problem with boxes/index. Time to write a profile test.

git checkout origin/profile_test

Look at the file “test/performance/boxes_index_test.rb”

# run, but it takes a long time, so I added the output to git
# ruby test/performance/boxes_index_test.rb

Open “tmp/performance/BoxesIndexTest#test_homepage_process_time_graph.html” in a browser Look at bold lines, scroll until a bold line is calling one of our processes

Create a benchmark test

git checkout origin/benchmark_test

Look at the file “test/performance/boxes_rank_test.rb”

RAILS_ENV=test rake db:drop db:create db:schema:load db:stories
ruby test/performance/boxes_rank_test.rb

Improve the code

git checkout origin/fixed_code

Look at the file “app/models/box.rb”

Fix the code, and use the benchmark to ensure that it is faster.

About

A guide to performance testing in rails

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published