Last active
August 29, 2015 14:02
-
-
Save jmervine/7b3ec1b6ee2c4a4b2382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'httperf' | |
require 'httperf/parser' | |
require 'yaml' | |
require 'pp' | |
#build test | |
def test(key) | |
rate = (@config['connections'] * (@config['tests'][key]['pct'] / 100.0)).round(2) | |
int = (((rate.to_i < 1) ? 1 : rate.to_i) * @config['duration']).to_i | |
opts = { | |
'parse' => true, | |
'rate' => rate, | |
'wsesslog' => "#{int},0,#{@config['tests'][key]['log']}" | |
}.merge(@config['httperf']) | |
return HTTPerf.new(opts) | |
end | |
@config = YAML.load_file('./httperf.yml') | |
# sample httperf.yml | |
# | |
#connections: 6 | |
#duration: 432000 | |
# | |
#tests: | |
# homepage: | |
# log: 'logs/hom.log' | |
# pct: 3 | |
# subpage: | |
# log: 'logs/sub.log' | |
# pct: 7 | |
# mainpage: | |
# log: 'logs/main.log' | |
# pct: 90 | |
# | |
#httperf: | |
# server: 'localhost' | |
# port: 3000 | |
# hog: true | |
# verbose: true | |
@httperf = {} | |
@threads = {} | |
@config['tests'].each_key do |key| | |
@httperf[key] = test(key) | |
puts @httperf[key].command | |
@threads[key] = @httperf[key].fork | |
end | |
@threads.each do |page, thread| | |
print "." until thread.join(1) | |
puts "Waiting." until thread.join(5) | |
end | |
@httperf.each do |page, perf| | |
puts " " | |
puts "#{page}" | |
puts "------------------------------------------------" | |
[ | |
:total_connections, | |
:connection_rate_per_sec, | |
:connection_time_avg, | |
:connection_time_median, | |
:connection_time_max, | |
:connection_time_85_pct, | |
:reply_status_2xx, | |
:reply_status_3xx, | |
:reply_status_4xx, | |
:reply_status_5xx, | |
:errors_total, | |
:errors_conn_reset | |
].each do |key| | |
puts "#{key}: #{perf.fork_out[key]}" | |
end | |
puts "------------------------------------------------" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment