add time it takes to load rails

This commit is contained in:
Sam 2013-08-15 16:35:57 +10:00
parent 8f5866d9e8
commit 40ef4b6907
1 changed files with 21 additions and 9 deletions

View File

@ -1,10 +1,19 @@
require "socket" require "socket"
require "csv" require "csv"
require "yaml"
@timings = {}
def run(command) def run(command)
system(command, out: $stdout, err: :out) system(command, out: $stdout, err: :out)
end end
def measure(name)
start = Time.now
yield
@timings[name] = ((Time.now - start) * 1000).to_i
end
def prereqs def prereqs
puts "Be sure to following packages are installed: puts "Be sure to following packages are installed:
@ -41,7 +50,13 @@ unless File.exists?("config/redis.yml")
`cp config/redis.yml.sample config/redis.yml` `cp config/redis.yml.sample config/redis.yml`
end end
# Github settings
ENV["RAILS_ENV"] = "profile" ENV["RAILS_ENV"] = "profile"
ENV["RUBY_GC_MALLOC_LIMIT"] = "1000000000"
ENV["RUBY_HEAP_SLOTS_GROWTH_FACTOR"] = "1.25"
ENV["RUBY_HEAP_MIN_SLOTS"] = "800000"
ENV["RUBY_FREE_MIN"] = "600000"
def port_available? port def port_available? port
server = TCPServer.open port server = TCPServer.open port
@ -62,17 +77,13 @@ puts `bundle exec rake db:create`
`bundle exec rake db:migrate` `bundle exec rake db:migrate`
puts "Loading Rails" puts "Loading Rails"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") measure("load_rails") do
`bundle exec rake middleware`
end
begin begin
unless pid = fork pid = spawn("bundle exec thin start -p #{port}")
require "rack"
Rack::Server.start(:config => "config.ru",
:AccessLog => [],
:Port => port)
exit
end
while port_available? port while port_available? port
sleep 1 sleep 1
@ -91,7 +102,8 @@ begin
puts "Your Results:" puts "Your Results:"
puts({ puts({
"home_page" => percentiles "home_page" => percentiles,
"timings" => @timings
}.to_yaml) }.to_yaml)
ensure ensure