Skip to content

Instantly share code, notes, and snippets.

@debugging
Created June 2, 2011 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debugging/1003822 to your computer and use it in GitHub Desktop.
Save debugging/1003822 to your computer and use it in GitHub Desktop.
ab example
#!/usr/bin/ruby
#url labels can only be /a-zA-Z0-9-/
urls = [
['Spreedemo-home', 'http://demo.spreecommerce.com/'],
['Spreedemo-product', 'http://demo.spreecommerce.com/products/xm-inno-xm2go-portable-satellite-radio-mp3-player-and-home-kit'],
['Google-home', 'http://www.google.com/'],
['Google-shopping', 'http://www.google.com/prdhp?hl=en&tab=vf']
]
n = 100
cons = [2, 20]
results = { "rps" => [], "tpr" => [] }
label_points = (0..urls.size-1).map { |i| "#{i*cons.size+cons.size/2}" }.join(',')
label_map = { "rps" => "Requests+per+second", "tpr" => "Time+per+Request+ms" }
labels = urls.collect { |i| i[0] }.join('|')
urls.each do |i|
cons.each do |c|
blah2 = `ab -n #{n} -c #{c} #{i[1]} | grep "Requests per\\|Time per req" | grep -v "concurrent"`
if blah2.match(/Requests per second:\s+(.*?) .*/)
results["rps"] << $1.to_f
end
if blah2.match(/Time per request:\s+(.*?) .*/)
results["tpr"] << $1.to_f
end
end
end
["rps", "tpr"].each do |type|
formatted_results = {}
results[type].each_with_index do |v, i|
con_index = (i%cons.size).to_s
formatted_results["i" + con_index] ||= []
formatted_results["i" + con_index] << v
end
max_buffer = results[type].max.to_i + 5
puts "http://chart.apis.google.com/chart?" +
"&chxl=1:|" + labels +
"&chxp=1,#{label_points}&chxr=0,0,#{max_buffer}|1,0,#{urls.size*cons.size}" +
"&chds=" +
cons.map { |c| "0,#{max_buffer}" }.join(',') +
"&chbh=a,0,0" +
"&chxt=y,x&chbh=a&chs=800x300&cht=bvg&chco=1A1F2B,30395C,4A6491,85A5CC&chd=t:" +
formatted_results.map { |k, v| v.join(',') }.join("|") +
"&chdl=" + cons.collect { |i| "Concurrency+#{i}" }.join("|") + "&chtt=" + label_map[type]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment