Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created September 28, 2009 09:38
Show Gist options
  • Save sinkovsky/195324 to your computer and use it in GitHub Desktop.
Save sinkovsky/195324 to your computer and use it in GitHub Desktop.
#!perl -w
use strict;
use warnings;
use Chart::Clicker;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Data::DataSet;
use Data::Dumper;
my $probix_host = "localhost";
my $probix_port = "8000";
my @tests = (
{
name => "objects",
description => "Fetch all objects",
url => "/objects/",
method => "GET",
data => "",
rate => "2000",
},
# {
# name => "object_probes",
# description => "Fetch all object probes",
# url => "/object/1/probes",
# method => "get",
# data => "",
# rate => "1000",
# }
);
sub usage {
}
sub run_all {
for my $test ( @tests ) {
my $max_rate = $test->{rate};
my $min_rate = $test->{rate} / 10;
my $rate_step = $test->{rate} / 10;
my @results;
for ( my $rate = $min_rate; $rate <= $max_rate; $rate += $rate_step ) {
$test->{rate} = $rate;
print "Running test with rate: $rate\n";
my $result = run_test($test);
push @results, $result;
}
output_chart($test->{name},\@results);
}
}
sub run_test {
my ($test) = @_;
my $output = `httperf --hog --server=$probix_host --port=$probix_port --uri=$test->{url} --rate=$test->{rate} --method=$test->{method} --num-conns=10000 --num-calls=1 --timeout 5`;
my $result = {};
print $output;
($result->{conns},
$result->{reqs},
$result->{replies}) =
$output =~ /Total: connections (\d+) requests (\d+) replies (\d+)/;
($result->{req_rate}) =
$output =~ /Request rate: ([\d.]+)/;
($result->{reply_rate}->{min},
$result->{reply_rate}->{avg},
$result->{reply_rate}->{max}) =
$output =~ /Reply rate.+?min ([\d.]+) avg ([\d.]+) max ([\d.]+)/;
($result->{reply_time}) =
$output =~ /Reply time.+response ([\d.]+)/;
print Dumper($result);
return $result;
}
sub output_chart {
my ($name, $results) = @_;
my $chart = Chart::Clicker->new;
my @keys = (1..@$results);
my @values = map { $_->{reply_time} } @$results;
my $series = Chart::Clicker::Data::Series->new(
keys => [ @keys ],
values => [ @values ],
);
@values = map { $_->{req_rate} } @$results;
my $series2 = Chart::Clicker::Data::Series->new(
keys => [ @keys ],
values => [ @values ],
);
my $dataset = Chart::Clicker::Data::DataSet->new(
series => [ $series, $series2 ],
);
# add the dataset to the chart
$chart->add_to_datasets($dataset);
# write the chart to a file
$chart->write_output("$name.png");
}
run_all;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment