Skip to content

Commit

Permalink
bench improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Jan 9, 2014
1 parent 74c1555 commit 1c3fc39
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
54 changes: 39 additions & 15 deletions script/bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@include_env = false
@result_file = nil
@iterations = 500
@best_of = 1
opts = OptionParser.new do |o|
o.banner = "Usage: ruby bench.rb [options]"

Expand All @@ -18,11 +19,18 @@
o.on("-i", "--iterations [ITERATIONS]", "Number of iterations to run the bench for") do |i|
@iterations = i.to_i
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
opts.parse!

def run(command)
system(command, out: $stdout, err: :out)
def run(command, opt = nil)
if opt == :quiet
system(command, out: "/dev/null", err: :out)
else
system(command, out: $stdout, err: :out)
end
end

begin
Expand Down Expand Up @@ -55,7 +63,7 @@ def prereqs
end

puts "Running bundle"
if !run("bundle")
if !run("bundle", :quiet)
puts "Quitting, some of the gems did not install"
prereqs
exit
Expand Down Expand Up @@ -151,16 +159,36 @@ def bench(path)
end

puts "Starting benchmark..."
append = "?api_key=#{api_key}&api_username=admin1"

# asset precompilation is a dog, wget to force it
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)"

Expand All @@ -176,17 +204,13 @@ def bench(path)

rss = `ps -o rss -p #{pid}`.chomp.split("\n").last.to_i

results = {
"home_page" => home_page,
"topic_page" => topic_page,
"home_page_admin" => home_page_admin,
"topic_page_admin" => topic_page_admin,
results.merge({
"timings" => @timings,
"ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
"rss_kb" => rss
}.merge(facts).to_yaml
}).merge(facts)

puts results
puts results.to_yaml

if @result_file
File.open(@result_file,"wb") do |f|
Expand Down
7 changes: 7 additions & 0 deletions script/profile_db_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def create_admin(seq)

require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

SiteSetting.queue_jobs = false

unless Rails.env == "profile"
puts "This script should only be used in the profile environment"
exit
Expand Down Expand Up @@ -104,3 +106,8 @@ def create_admin(seq)
putc "."
PostCreator.create(users.sample, raw: sentence, topic_id: topic_ids.sample, skip_validations: true)
end

# no sidekiq so update some stuff
Category.update_stats
Jobs::PeriodicalUpdates.new.execute(nil)

0 comments on commit 1c3fc39

Please sign in to comment.