- Timestamp:
- Mar 6, 2014 2:53:13 PM (11 years ago)
- Branches:
- master
- Children:
- 8c96802
- Parents:
- 0035554
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
misc/httpbench.pl
r0035554 r560dfd2 8 8 use Parallel::ForkManager; 9 9 use LWP::Simple; 10 use Time::HiRes qw(sleep );10 use Time::HiRes qw(sleep gettimeofday); 11 11 12 12 usage() if (@ARGV == 0); … … 32 32 warn "$num urls with $concurrency clients, $loops loops\n"; 33 33 warn "Total: ", $num * $concurrency * $loops, " requests\n"; 34 warn "wait for $wait second between requests\n" ;34 warn "wait for $wait second between requests\n" if ($wait); 35 35 36 36 37 my $transfer = 0; 38 my $pm = Parallel::ForkManager->new($concurrency); 39 $pm->run_on_finish( 40 sub { 41 my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $dataref) = @_; 42 if (defined $dataref) { 43 $transfer += $$dataref; 44 } 45 } 46 ); 37 47 38 my $pm = Parallel::ForkManager->new($concurrency); 39 for (my $child = 0; $child < $concurrency; $child++) { 40 if ($pm->start) { 41 warn "forks $child/$concurrency child ...\n"; 42 next; 48 my ($startsec, $startmicro) = gettimeofday(); 49 { 50 use bytes; 51 for (my $child = 0; $child < $concurrency; $child++) { 52 if ($pm->start) { 53 warn "forks $child/$concurrency child ...\n"; 54 next; 55 } 56 my $transfer = 0; 57 for (my $i = 0; $i < $loops; $i++) { 58 print STDERR "processing $i/$loops loop\r"; 59 foreach my $url (@urls) { 60 my $res = get($url) or print STDERR "\nfail: $url"; 61 if ($res) { 62 $transfer += length($res); 63 } 64 sleep($wait); 65 } 66 } 67 $pm->finish(0, \$transfer); 43 68 } 44 for (my $i = 0; $i < $loops; $i++) { 45 print STDERR "processing $i/$loops loop\r"; 46 foreach my $url (@urls) { 47 get($url) or warn "fail: $url\n"; 48 sleep($wait); 49 } 50 } 51 $pm->finish; 69 $pm->wait_all_children; 52 70 } 53 $pm->wait_all_children; 71 my ($endsec, $endmicro) = gettimeofday(); 72 my $elapsed = ($endsec - $startsec) + ($endmicro - $startmicro) / 10**6; 73 my $bytepersec = $transfer / $elapsed; 74 75 my @units = qw( B/s KiB/s MiB/s GiB/s ); 76 my $unit = 0; 77 while ($bytepersec > 1024) { 78 $bytepersec /= 1024; 79 $unit++; 80 } 81 $bytepersec = sprintf("%.4g", $bytepersec); 54 82 55 83 warn "\n ...done.\n"; 56 84 warn "get $transfer bytes in $elapsed seconds ($bytepersec $units[$unit])\n"; 57 85 58 86 sub usage {
Note: See TracChangeset
for help on using the changeset viewer.