From 1c3fc39525b4dde3cd6036a811ab26c98dc1f520 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 9 Jan 2014 15:56:03 +1100 Subject: [PATCH] bench improvements --- script/bench.rb | 54 ++++++++++++++++++++++++---------- script/profile_db_generator.rb | 7 +++++ 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/script/bench.rb b/script/bench.rb index 76a207d0b..9df552290 100644 --- a/script/bench.rb +++ b/script/bench.rb @@ -6,6 +6,7 @@ require "optparse" @include_env = false @result_file = nil @iterations = 500 +@best_of = 1 opts = OptionParser.new do |o| 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| @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 @@ -55,7 +63,7 @@ sudo apt-get install redis-server end puts "Running bundle" -if !run("bundle") +if !run("bundle", :quiet) puts "Quitting, some of the gems did not install" prereqs exit @@ -151,16 +159,36 @@ begin 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)" @@ -176,17 +204,13 @@ begin 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| diff --git a/script/profile_db_generator.rb b/script/profile_db_generator.rb index 0a53fc09a..2b420b935 100644 --- a/script/profile_db_generator.rb +++ b/script/profile_db_generator.rb @@ -56,6 +56,8 @@ end 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 @@ -104,3 +106,8 @@ puts "creating 2000 replies" 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) +