bench improvements

This commit is contained in:
Sam 2014-01-09 15:56:03 +11:00
parent 74c1555885
commit 1c3fc39525
2 changed files with 46 additions and 15 deletions

View File

@ -6,6 +6,7 @@ require "optparse"
@include_env = false @include_env = false
@result_file = nil @result_file = nil
@iterations = 500 @iterations = 500
@best_of = 1
opts = OptionParser.new do |o| opts = OptionParser.new do |o|
o.banner = "Usage: ruby bench.rb [options]" o.banner = "Usage: ruby bench.rb [options]"
@ -18,11 +19,18 @@ opts = OptionParser.new do |o|
o.on("-i", "--iterations [ITERATIONS]", "Number of iterations to run the bench for") do |i| o.on("-i", "--iterations [ITERATIONS]", "Number of iterations to run the bench for") do |i|
@iterations = i.to_i @iterations = i.to_i
end end
o.on("-b", "--best_of [NUM]", "Number of times to run the bench taking best as result") do |i|
@best_of = i.to_i
end
end end
opts.parse! opts.parse!
def run(command) def run(command, opt = nil)
system(command, out: $stdout, err: :out) if opt == :quiet
system(command, out: "/dev/null", err: :out)
else
system(command, out: $stdout, err: :out)
end
end end
begin begin
@ -55,7 +63,7 @@ sudo apt-get install redis-server
end end
puts "Running bundle" puts "Running bundle"
if !run("bundle") if !run("bundle", :quiet)
puts "Quitting, some of the gems did not install" puts "Quitting, some of the gems did not install"
prereqs prereqs
exit exit
@ -151,16 +159,36 @@ begin
end end
puts "Starting benchmark..." puts "Starting benchmark..."
append = "?api_key=#{api_key}&api_username=admin1"
# asset precompilation is a dog, wget to force it # asset precompilation is a dog, wget to force it
run "wget http://127.0.0.1:#{@port}/ -o tmp/test.html" run "wget http://127.0.0.1:#{@port}/ -o tmp/test.html"
home_page = bench("/")
topic_page = bench("/t/oh-how-i-wish-i-could-shut-up-like-a-tunnel-for-so/69")
append = "?api_key=#{api_key}&api_username=admin1" tests = [
["home", "/"],
["topic", "/t/oh-how-i-wish-i-could-shut-up-like-a-tunnel-for-so/69"],
# ["user", "/users/admin1/activity"],
["categories", "/categories"]
]
tests += tests.map{|k,url| ["#{k}_admin", "#{url}#{append}"]}
tests.shuffle
def best_of(a, b)
return a unless b
return b unless a
a[50] < b[50] ? a : b
end
results = {}
@best_of.times do
tests.each do |name, url|
results[name] = best_of(bench(url),results[name])
end
end
home_page_admin = bench("/#{append}")
topic_page_admin = bench("/t/oh-how-i-wish-i-could-shut-up-like-a-tunnel-for-so/69#{append}")
puts "Your Results: (note for timings- percentile is first, duration is second in millisecs)" puts "Your Results: (note for timings- percentile is first, duration is second in millisecs)"
@ -176,17 +204,13 @@ begin
rss = `ps -o rss -p #{pid}`.chomp.split("\n").last.to_i rss = `ps -o rss -p #{pid}`.chomp.split("\n").last.to_i
results = { results.merge({
"home_page" => home_page,
"topic_page" => topic_page,
"home_page_admin" => home_page_admin,
"topic_page_admin" => topic_page_admin,
"timings" => @timings, "timings" => @timings,
"ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}", "ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
"rss_kb" => rss "rss_kb" => rss
}.merge(facts).to_yaml }).merge(facts)
puts results puts results.to_yaml
if @result_file if @result_file
File.open(@result_file,"wb") do |f| File.open(@result_file,"wb") do |f|

View File

@ -56,6 +56,8 @@ end
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
SiteSetting.queue_jobs = false
unless Rails.env == "profile" unless Rails.env == "profile"
puts "This script should only be used in the profile environment" puts "This script should only be used in the profile environment"
exit exit
@ -104,3 +106,8 @@ puts "creating 2000 replies"
putc "." putc "."
PostCreator.create(users.sample, raw: sentence, topic_id: topic_ids.sample, skip_validations: true) PostCreator.create(users.sample, raw: sentence, topic_id: topic_ids.sample, skip_validations: true)
end end
# no sidekiq so update some stuff
Category.update_stats
Jobs::PeriodicalUpdates.new.execute(nil)