Skip to content

Instantly share code, notes, and snippets.

@banyan
Last active December 11, 2015 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyan/4664763 to your computer and use it in GitHub Desktop.
Save banyan/4664763 to your computer and use it in GitHub Desktop.
require 'gruff'
concurrencies = {
0 => "1",
1 => "10",
2 => "20",
3 => "50",
4 => "100"
}
titles = [
{ key: :request, description: "Requests per second" },
{ key: :time, description: "Time per request" }
]
targets = [
{ host: "test1.com", description: "php-fpm + nginx" },
{ host: "test2.com", description: "php-fpm + apache2.2" },
{ host: "test3.com", description: "apache2.2 (mod_php)" },
{ host: "test4.com", description: "php-fpm + apache2.4" },
{ host: "test5.com", description: "apache2.4 (mod_php)" }
]
loop_count = 1
request_times = 1000
titles.each do |title|
regex = (title[:key] == :request) ? /Requests per second:\s*(.+?) \[/ : /Time per request:\s*(.+?) \[ms\] \(mean\)/
targets.each do |target|
target[:results] = concurrencies.values.map do |concurrency|
results = []
loop_count.times do
`ab -n #{request_times} -c #{concurrency} http://#{target[:host]}/bench.php` =~ regex
results << $1.to_f
end
average = results.map(&:to_f).inject(0.0) { |r, i| r += i } / results.size
("%0.2f" % average).to_f
end
end
# targets = [{:host=>"test1.com", :description=>"php-fpm + nginx", :results=>["40.89", "190.78", "270.74"]}, {:host=>"test2.com", :description=>"php-fpm + apache2.2", :results=>["29.81", "176.78", "217.16"]}, {:host=>"test3.com", :description=>"apache2.2 (mod_php)", :results=>["30.20", "165.30", "205.03"]}, {:host=>"test4.com", :description=>"php-fpm + apache2.4", :results=>["28.70", "158.23", "217.65"]}, {:host=>"test5.com", :description=>"apache2.4 (mod_php)", :results=>["41.54", "169.19", "265.83"]}]
# output STDOUT
puts title[:description]
targets.each do |target|
puts "#{target[:description]}, #{target[:results]}"
end
# create graph
g = Gruff::Line.new
g.title = title[:description]
targets.each do |target|
g.data(target[:description], target[:results])
end
g.labels = concurrencies
file_name = "#{title[:key]}_#{Time.now.strftime("%Y%m%d-%H%M%S")}.png"
g.write(file_name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment