From 178d57852047dbd7e304480086116820b29b60f1 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Thu, 6 Mar 2014 18:19:23 +0900 Subject: [PATCH] new option --duration * set loop duration time (second) * with --duration, --loops is ignored --- misc/httpbench.pl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/misc/httpbench.pl b/misc/httpbench.pl index 0781a38..5fdd9fb 100755 --- a/misc/httpbench.pl +++ b/misc/httpbench.pl @@ -16,6 +16,7 @@ GetOptions( 'i|inputfile=s' => \ my $file, 'c|concurrency=i' => \ my $concurrency, 'n|loops=i' => \ my $loops, + 'd|duration=i' => \ my $duration, 'w|wait=f' => \ my $wait, ) or usage(); @@ -23,14 +24,16 @@ usage() if $help; $concurrency ||= 1; $loops ||= 1; +$duration ||= 0; $wait ||= 0; my @urls = file2urls($file) if ($file); push @urls, @ARGV; my $num = scalar @urls; -warn "$num urls with $concurrency clients, $loops loops\n"; -warn "Total: ", $num * $concurrency * $loops, " requests\n"; +my $l = ($duration) ? "$duration seconds loops" : "$loops loops"; +warn "$num urls with $concurrency clients, $l\n"; +warn "Total: ", $num * $concurrency * $loops, " requests\n" if (! $duration); warn "wait for $wait second between requests\n" if ($wait); my $ua = LWP::UserAgent->new( @@ -57,7 +60,15 @@ for (my $child = 0; $child < $concurrency; $child++) { else { # child my $transfer = 0; - for (my $i = 0; $i < $loops; $i++) { + my $i = 0; + while (1) { + if ($duration) { + last if (time() - $startsec > $duration); + } + else { + last if ($i >= $loops); + } + print STDERR "processing $i/$loops loop\r"; foreach my $url (@urls) { my $res = $ua->get($url); @@ -69,6 +80,8 @@ for (my $child = 0; $child < $concurrency; $child++) { } sleep($wait); } + + $i++; } $pm->finish(0, \$transfer); } -- 1.7.9.5