#!/usr/bin/env ruby # Runs ApacheBench a preset number of times and outputs the mean request time as CSV # # Bryant Casteel # http://bethings.postplatinum.com/tag/ab-time-chart/ # 2010-12-05 # configuration MIN_CONNECTIONS = 1 MAX_CONNECTIONS = 1000 TARGET_SAMPLES = 100 # output the column headings print '""' $*.each do |url| print ",\"#{url}\"" end puts # output row of zeroes for origin print '0' $*.length.times do print ',0' end puts # for increasing number of concurrent connections interval = 1 connections = MIN_CONNECTIONS while connections <= MAX_CONNECTIONS do # output the row heading print connections # test each URL $*.each do |url| mean_time = nil samples = TARGET_SAMPLES # keep trying in the event of a failure while mean_time.nil? and (samples > 0) hits = connections * samples if /Time per request.*?([\d\.]+).*(mean)/ =~ `ab -n #{hits} -c #{connections} "#{url}"` # store just the mean request time upon success mean_time = $1 else # try fewer samples upon failure samples = (samples * 0.5).to_i end end if mean_time.nil? # fill in missing data in chart mean_time = '=NA()' end print ",#{mean_time}" end # end the row puts # calculate next increment if (connections / (interval * 10)) >= 1 # increment the connections by increasing powers of 10 interval = interval * 10 end connections = connections + interval end