HTTPerf.rb Example

Here's an example of a simple script using HTTPerf.rb. It's a quick and dirty script used for getting quick differences between changes.

#!/usr/bin/env ruby
require 'json'
require 'httperf'
# gem install httperfrb
# see:

server = ENV['HTTPERF_HOST']  || "localhost"
uri    = ENV['HTTPERF_URI']   || "/"
conns  = ENV['HTTPERF_CONNS'] || 10

httperf = "server" => server, "num-conns" => conns, "uri" => uri, "rate" => 1, "verbose" => true, "parse" => true )

puts "Starting: #{httperf.command}"

file = "test-#{"%Y%jT%H%M%S")}"

result ="#{file}.json", "w") do |f|
  f.print result.to_json
end"#{file}.txt", "w") do |f|
  [ :total_connections,
    :connection_time_99_pct ].each do |k|

    title = k.to_s.gsub("_", " ").capitalize+":"

    f.printf "%-25s %s\n", title, result[k].to_s
    printf "%-25s %s\n",   title, result[k].to_s

puts "Done!"

get the gist