mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
allow bench to run with unicorn optionally
memstats can output yaml now
This commit is contained in:
parent
f7d5a561ec
commit
c0d947aa98
4 changed files with 47 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
||||||
if ENV['UNICORN_ENABLE_OOBGC']
|
if ENV['UNICORN_ENABLE_OOBGC'] == '1'
|
||||||
require 'middleware/unicorn_oobgc'
|
require 'middleware/unicorn_oobgc'
|
||||||
Middleware::UnicornOobgc.init
|
Middleware::UnicornOobgc.init
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
|
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
|
||||||
|
|
||||||
# enable out of band gc out of the box, it is low risk and improves perf a lot
|
# enable out of band gc out of the box, it is low risk and improves perf a lot
|
||||||
ENV['UNICORN_ENABLE_OOBGC'] = "1"
|
ENV['UNICORN_ENABLE_OOBGC'] ||= "1"
|
||||||
|
|
||||||
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ worker_processes (ENV["UNICORN_WORKERS"] || 3).to_i
|
||||||
working_directory discourse_path
|
working_directory discourse_path
|
||||||
|
|
||||||
# listen "#{discourse_path}/tmp/sockets/unicorn.sock"
|
# listen "#{discourse_path}/tmp/sockets/unicorn.sock"
|
||||||
listen 3000
|
listen (ENV["UNICORN_PORT"] || 3000).to_i
|
||||||
|
|
||||||
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
||||||
timeout 30
|
timeout 30
|
||||||
|
|
|
@ -8,6 +8,7 @@ require "optparse"
|
||||||
@iterations = 500
|
@iterations = 500
|
||||||
@best_of = 1
|
@best_of = 1
|
||||||
@mem_stats = false
|
@mem_stats = false
|
||||||
|
@unicorn = false
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: ruby bench.rb [options]"
|
o.banner = "Usage: ruby bench.rb [options]"
|
||||||
|
@ -27,6 +28,9 @@ opts = OptionParser.new do |o|
|
||||||
o.on("-m", "--memory_stats") do
|
o.on("-m", "--memory_stats") do
|
||||||
@mem_stats = true
|
@mem_stats = true
|
||||||
end
|
end
|
||||||
|
o.on("-u", "--unicorn", "Use unicorn to serve pages as opposed to thin") do
|
||||||
|
@unicorn = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
opts.parse!
|
opts.parse!
|
||||||
|
|
||||||
|
@ -140,7 +144,9 @@ api_key = `bundle exec rake api_key:get`.split("\n")[-1]
|
||||||
|
|
||||||
def bench(path)
|
def bench(path)
|
||||||
puts "Running apache bench warmup"
|
puts "Running apache bench warmup"
|
||||||
`ab -n 10 "http://127.0.0.1:#{@port}#{path}"`
|
add = ""
|
||||||
|
add = "-c 3 " if @unicorn
|
||||||
|
`ab #{add} -n 10 "http://127.0.0.1:#{@port}#{path}"`
|
||||||
puts "Benchmarking #{path}"
|
puts "Benchmarking #{path}"
|
||||||
`ab -n #{@iterations} -e tmp/ab.csv "http://127.0.0.1:#{@port}#{path}"`
|
`ab -n #{@iterations} -e tmp/ab.csv "http://127.0.0.1:#{@port}#{path}"`
|
||||||
|
|
||||||
|
@ -157,7 +163,12 @@ begin
|
||||||
puts "precompiling assets"
|
puts "precompiling assets"
|
||||||
run("bundle exec rake assets:precompile")
|
run("bundle exec rake assets:precompile")
|
||||||
|
|
||||||
pid = spawn("bundle exec thin start -p #{@port}")
|
pid = if @unicorn
|
||||||
|
ENV['UNICORN_PORT'] = @port.to_s
|
||||||
|
spawn("bundle exec unicorn -c config/unicorn.conf.rb")
|
||||||
|
else
|
||||||
|
spawn("bundle exec thin start -p #{@port}")
|
||||||
|
end
|
||||||
|
|
||||||
while port_available? @port
|
while port_available? @port
|
||||||
sleep 1
|
sleep 1
|
||||||
|
@ -208,14 +219,29 @@ begin
|
||||||
|
|
||||||
run("RAILS_ENV=profile bundle exec rake assets:clean")
|
run("RAILS_ENV=profile bundle exec rake assets:clean")
|
||||||
|
|
||||||
rss = `ps -o rss -p #{pid}`.chomp.split("\n").last.to_i
|
def get_mem(pid)
|
||||||
|
YAML.load `ruby script/memstats.rb #{pid} --yaml`
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
mem = get_mem(pid)
|
||||||
|
|
||||||
results = results.merge({
|
results = results.merge({
|
||||||
"timings" => @timings,
|
"timings" => @timings,
|
||||||
"ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
|
"ruby-version" => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}",
|
||||||
"rss_kb" => rss
|
"rss_kb" => mem["rss_kb"],
|
||||||
|
"pss_kb" => mem["pss_kb"]
|
||||||
}).merge(facts)
|
}).merge(facts)
|
||||||
|
|
||||||
|
if @unicorn
|
||||||
|
child_pids = `ps --ppid #{pid} | awk '{ print $1; }' | grep -v PID`.split("\n")
|
||||||
|
child_pids.each do |child|
|
||||||
|
mem = get_mem(child)
|
||||||
|
results["rss_kb_#{child}"] = mem["rss_kb"]
|
||||||
|
results["pss_kb_#{child}"] = mem["pss_kb"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
puts results.to_yaml
|
puts results.to_yaml
|
||||||
|
|
||||||
if @mem_stats
|
if @mem_stats
|
||||||
|
|
|
@ -127,10 +127,18 @@ def get_commandline( pid )
|
||||||
return commandline.join(' ')
|
return commandline.join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ARGV.include? '--yaml'
|
||||||
puts "#{"Process:".ljust(20)} #{pid}"
|
require 'yaml'
|
||||||
puts "#{"Command Line:".ljust(20)} #{get_commandline(pid)}"
|
puts Hash[*totals.map do |k,v|
|
||||||
puts "Memory Summary:"
|
[k + '_kb', v]
|
||||||
totals.keys.sort.each do |k|
|
end.flatten].to_yaml
|
||||||
puts " #{k.ljust(20)} #{format_number( totals[k] ).rjust(12)} kB"
|
else
|
||||||
|
puts "#{"Process:".ljust(20)} #{pid}"
|
||||||
|
puts "#{"Command Line:".ljust(20)} #{get_commandline(pid)}"
|
||||||
|
puts "Memory Summary:"
|
||||||
|
totals.keys.sort.each do |k|
|
||||||
|
puts " #{k.ljust(20)} #{format_number( totals[k] ).rjust(12)} kB"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue