projects
/
lab.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0035554
)
measure the transfer data size and elapsed time
author
Ken-ichi Mito
<mitty@mitty.jp>
Thu, 6 Mar 2014 05:53:13 +0000
(14:53 +0900)
committer
Ken-ichi Mito
<mitty@mitty.jp>
Thu, 6 Mar 2014 05:53:13 +0000
(14:53 +0900)
misc/httpbench.pl
patch
|
blob
|
history
diff --git
a/misc/httpbench.pl
b/misc/httpbench.pl
index
78191dd
..
6f2e04d
100755
(executable)
--- a/
misc/httpbench.pl
+++ b/
misc/httpbench.pl
@@
-7,7
+7,7
@@
use utf8;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
use Parallel::ForkManager;
use LWP::Simple;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
use Parallel::ForkManager;
use LWP::Simple;
-use Time::HiRes qw(sleep);
+use Time::HiRes qw(sleep gettimeofday);
usage() if (@ARGV == 0);
usage() if (@ARGV == 0);
@@
-31,29
+31,57
@@
push @urls, @ARGV;
my $num = scalar @urls;
warn "$num urls with $concurrency clients, $loops loops\n";
warn "Total: ", $num * $concurrency * $loops, " requests\n";
my $num = scalar @urls;
warn "$num urls with $concurrency clients, $loops loops\n";
warn "Total: ", $num * $concurrency * $loops, " requests\n";
-warn "wait for $wait second between requests\n";
-
+warn "wait for $wait second between requests\n" if ($wait);
+my $transfer = 0;
my $pm = Parallel::ForkManager->new($concurrency);
my $pm = Parallel::ForkManager->new($concurrency);
-for (my $child = 0; $child < $concurrency; $child++) {
- if ($pm->start) {
- warn "forks $child/$concurrency child ...\n";
- next;
+$pm->run_on_finish(
+ sub {
+ my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $dataref) = @_;
+ if (defined $dataref) {
+ $transfer += $$dataref;
+ }
}
}
- for (my $i = 0; $i < $loops; $i++) {
- print STDERR "processing $i/$loops loop\r";
- foreach my $url (@urls) {
- get($url) or warn "fail: $url\n";
- sleep($wait);
- }
+);
+
+my ($startsec, $startmicro) = gettimeofday();
+{
+ use bytes;
+ for (my $child = 0; $child < $concurrency; $child++) {
+ if ($pm->start) {
+ warn "forks $child/$concurrency child ...\n";
+ next;
}
}
- $pm->finish;
+ my $transfer = 0;
+ for (my $i = 0; $i < $loops; $i++) {
+ print STDERR "processing $i/$loops loop\r";
+ foreach my $url (@urls) {
+ my $res = get($url) or print STDERR "\nfail: $url";
+ if ($res) {
+ $transfer += length($res);
+ }
+ sleep($wait);
+ }
+ }
+ $pm->finish(0, \$transfer);
+ }
+ $pm->wait_all_children;
}
}
-$pm->wait_all_children;
+my ($endsec, $endmicro) = gettimeofday();
+my $elapsed = ($endsec - $startsec) + ($endmicro - $startmicro) / 10**6;
+my $bytepersec = $transfer / $elapsed;
-warn "\n ...done.\n";
+my @units = qw( B/s KiB/s MiB/s GiB/s );
+my $unit = 0;
+while ($bytepersec > 1024) {
+ $bytepersec /= 1024;
+ $unit++;
+}
+$bytepersec = sprintf("%.4g", $bytepersec);
+warn "\n ...done.\n";
+warn "get $transfer bytes in $elapsed seconds ($bytepersec $units[$unit])\n";
sub usage {
warn "$0 -i urls.txt -c concurrency -n loops -w wait_interval\n",
sub usage {
warn "$0 -i urls.txt -c concurrency -n loops -w wait_interval\n",