Skip to content

Instantly share code, notes, and snippets.

@christos
Created July 23, 2010 16:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christos/487687 to your computer and use it in GitHub Desktop.
Save christos/487687 to your computer and use it in GitHub Desktop.
# Clone rails from github
git clone git://github.com/rails/rails.git ~/Desktop/rails
cd ~/Desktop/rails
# Create a 2.3.8 vanila app
git co v2.3.8
ruby ./railties/bin/rails ~/Desktop/rails2app
# Generate some models and a controller
cd ~/Desktop/rails2app
script/generate model post title:string
script/generate model tag name:string
script/generate model tagging post_id:integer tag_id:integer
script/generate controller posts index
# Update the following files:
# # app/models/post.rb
# class Post < ActiveRecord::Base
# has_many :taggings
# has_many :tags, :through => :taggings
# end
# # app/models/tag.rb
# class Tag < ActiveRecord::Base
# has_many :taggings
# has_many :posts, :through => :taggings
# end
# # app/models/tagging.rb
# class Tagging < ActiveRecord::Base
# belongs_to :post
# belongs_to :tag
# end
# # app/views/posts/index.html.erb
#<ul>
# <% Post.all.each do |post| %>
# <li><%= post.title %> <%= post.tags.count %></li>
# <% end %>
#</ul>
# # db/seeds.rb
# 1.upto(20) do |i|
# t = Tag.create :name => "Tag #{i}"
# 1.upto(50) do |j|
# p = Post.create :title => "Post #{j} with tag #{t.name}"
# t.posts << p
# end
# end
# Migrate and seed the DB
rake db:migrate db:seed
# Crate a Rails 3 edge vanila app
cd ~/Desktop/rails
git co master
ruby bin/rails new ~/Desktop/rails3app --dev
cd ~/Desktop/rails3app
rails generate model post title:string
rails generate model tag name:string
rails generate model tagging post_id:integer tag_id:integer
rails generate controller posts index
# Copy the same models and controller from above
cp -R ~/Desktop/rails2app/app/models/*.rb ~/Desktop/rails3app/app/models
cp -R ~/Desktop/rails2app/app/controllers/posts_controller.rb ~/Desktop/rails3app/app/controllers
cp -R ~/Desktop/rails2app/app/views/posts/index.html.erb ~/Desktop/rails3app/app/views/posts
cp -R ~/Desktop/rails2app/db/seeds.rb ~/Desktop/rails3app/db
# Migrate and seed the DB
rake db:migrate db:seed
# Start both servers
cd ~/Desktop/rails2app
script/server webrick -p 3002
cd ~/Desktop/rails3app
rails server -p 3003
# On my Macbook Air:
# Visit http://localhost:4002/posts/index with your browser
# log/development.log:
# Completed in 1829ms (View: 1320, DB: 508) | 200 OK [http://localhost/posts/index]
# Visit http://localhost:4003/posts/index
# log/development.log:
# Completed 200 OK in 3ms (Views: 4357.1ms | ActiveRecord: 397.3ms)
# Rails 3 vs Rails 2.3.8 is ~3.5 times SLOWER?
cd ~/Desktop/rails3app
RAILS_ENV=production rake db:drop db:create db:migrate db:seed
RAILS_ENV=production rails server -p 4003
httperf --server localhost --port 4003 --uri /posts/index --num-conns 20
# Connection rate: 0.1 conn/s (8602.0 ms/conn, <=1 concurrent connections)
# Connection time [ms]: min 5016.9 avg 8602.0 max 13908.5 median 8008.5 stddev 2127.2
# Connection time [ms]: connect 0.3
# Connection length [replies/conn]: 1.000
# Request rate: 0.1 req/s (8602.0 ms/req)
cd ~/Desktop/rails2app
RAILS_ENV=production rake db:drop db:create db:migrate db:seed
RAILS_ENV=production script/server webrick -p 4002
httperf --server localhost --port 4002 --uri /posts/index --num-conns 20
# Connection rate: 0.3 conn/s (3108.4 ms/conn, <=1 concurrent connections)
# Connection time [ms]: min 2027.5 avg 3108.4 max 3629.3 median 3170.5 stddev 397.9
# Connection time [ms]: connect 0.4
# Connection length [replies/conn]: 1.000
# Request rate: 0.3 req/s (3108.4 ms/req)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment