You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2010/04/12 17:51:06 UTC

[Solr Wiki] Update of "BenchmarkingSolr" by ShawnHeisey

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.

The "BenchmarkingSolr" page has been changed by ShawnHeisey.
http://wiki.apache.org/solr/BenchmarkingSolr

--------------------------------------------------

New page:
= Benchmarking Solr =

== Perl script (originally by ShawnHeisey) ==

It's not very polished.  Requires the Time::Hi``Res, Statistics::Descriptive, IO::Handle, and LWP::Simple Perl modules.  As written, it will not work on Windows.  If you wish to include the time required to write the query results to disk, there are some lines commented, just uncomment them.  Although it does provide an average request time, I believe the median, 95th percentile, and 99th percentile values it outputs are more useful.

{{{
#!ignoreme
#!/usr/bin/perl

#--- start config ---
my $forkCount = 8;
my $queryCount = 512;
my $outputDir = "/tmp/zot";
my $querySource = "/usr/local/etc/queries";
my $urlHost = "localhost";
my $urlPort = "8983";
my $urlCore = "live/"; # set to "" to not use a core
my $urlOptions = "rows=50&fl=score,*";
#---- end config ----

use strict;
use warnings qw(all);
use Time::HiRes qw ( time alarm sleep );
use Statistics::Descriptive;
use IO::Handle;
use LWP::Simple;

my %kids;
my $pid;
my $i;
#my $j = 0;
my $r;
my $query;
my @queries;
my $size;
my $num;
my $veryStart = time();
my $start;
my $elapsed;
my $stat;
my %cfg;

my $urlTemplate = "http://HOST:PORT/solr/COREselect/?q=QUERY&OPTIONS";
my $url;

###
### Main routine
###

#mkdir "$outputDir/result";
system "rm -f $outputDir/* 2> /dev/null" if length $outputDir;
#system "rm -f $outputDir/result/* 2> /dev/null" if length $outputDir;

$urlTemplate =~ s/HOST/$urlHost/;
$urlTemplate =~ s/PORT/$urlPort/;
$urlTemplate =~ s/CORE/$urlCore/;
$urlTemplate =~ s/OPTIONS/$urlOptions/;

for ($i = 0; $i < $forkCount; $i++) {
  $pid = fork();
  if ($pid) {
    $kids{$pid} = 1;
  } else {
    @queries = `cat $querySource`;
    $size = @queries;

    open OUT, ">$outputDir/$$.hammer";
    OUT->autoflush(1);
    for ($i = 0; $i < $queryCount; $i++) {
      $num = int(rand $size);
      $query = $queries[$num];
      chomp $query;

      $url = $urlTemplate;
      $url =~ s/QUERY/$query/;

      $start = time();
      $r = get ($url);
      if (defined $r and $r) {
        $elapsed = time() - $start;
        print OUT "$elapsed\n";
  #      open R, ">$outputDir/result/$$.$j";
  #      print R $r;
  #      close R;
  #      $j++;
      }
    }
    close OUT;
    exit 0;
  }
}

foreach (keys %kids) {
  waitpid($_, 0);
}

$stat = Statistics::Descriptive::Full->new();
foreach $i (keys %kids) {
  open IN, "<$outputDir/$i.hammer";
  while (<IN>) {
    chomp;
    $stat->add_data($_);
  }
  close IN;
}

system "rm -f $outputDir/* 2> /dev/null" if length $outputDir;
system "rm -f $outputDir/result/* 2> /dev/null" if length $outputDir;

printf " Req/s: %1.03f (%1.03f sec, requests %d/%d)\n"
  , $stat->count() / (time() - $veryStart)
  , time() - $veryStart, $stat->count(), $forkCount * $queryCount;
printf "   Avg: %1.03f\n", $stat->mean();
printf "Median: %1.03f\n", $stat->median();
printf "  95th: %1.03f\n", $stat->percentile(95);
printf "  99th: %1.03f\n", $stat->percentile(99);
print "\n";

exit 0;
}}}

Sample output:
{{{
 Req/s: 144.035 (28.188 sec, requests 4060/4096)
   Avg: 0.052
Median: 0.040
  95th: 0.131
  99th: 0.237
}}}