From df5ee19e171aab5361e9154755bf9863e4bdf310 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Sun, 24 May 2015 00:09:37 +0900 Subject: [PATCH] remove benchmark script * split repository to https://github.com/mittyorz/benchmark --- misc/dnsbench.pl | 50 --------------------- misc/httpbench.pl | 126 ----------------------------------------------------- 2 files changed, 176 deletions(-) delete mode 100644 misc/dnsbench.pl delete mode 100755 misc/httpbench.pl diff --git a/misc/dnsbench.pl b/misc/dnsbench.pl deleted file mode 100644 index 65bdbdb..0000000 --- a/misc/dnsbench.pl +++ /dev/null @@ -1,50 +0,0 @@ -#! /usr/bin/perl -w - -use strict; -use warnings; - -use Net::DNS; - -my $hostlist = shift @ARGV or die "usage: $0 list_of_hosts [nameserver]"; -if (! -r $hostlist) { - die "$0: cannot read $hostlist"; -} -my $nameserver = shift @ARGV; - -my $res; -if ($nameserver) { - warn "$0: performing DNS query with server($nameserver)"; - $res = Net::DNS::Resolver->new( - nameservers => [$nameserver], - ); -} -else { - warn "$0: use system default nameservers"; - $res = Net::DNS::Resolver->new; -} - - -open my $list, '<', $hostlist or die "$0: filename: $!"; -while (my $host = <$list>) { - chomp $host; - my $query = $res->send($host); - if ($query) { - print "$host -> "; - if ($res->errorstring ne 'NOERROR') { - print $res->errorstring, "\n"; - next; - } - foreach my $rr ($query->answer) { - if ($rr->type eq 'A') { - print $rr->address, " "; - } - elsif ($rr->type eq 'PTR') { - print $rr->ptrdname, " "; - } - } - print "\n"; - } - else { - warn "$0: query failed: ", $res->errorstring, "\n"; - } -} diff --git a/misc/httpbench.pl b/misc/httpbench.pl deleted file mode 100755 index 5fdd9fb..0000000 --- a/misc/httpbench.pl +++ /dev/null @@ -1,126 +0,0 @@ -#! /usr/bin/perl -w - -use strict; -use warnings; -use utf8; - -use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat); -use Parallel::ForkManager; -use LWP::UserAgent; -use Time::HiRes qw(sleep gettimeofday); - -usage() if (@ARGV == 0); - -GetOptions( - 'h|help' => \ my $help, - '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(); - -usage() if $help; - -$concurrency ||= 1; -$loops ||= 1; -$duration ||= 0; -$wait ||= 0; - -my @urls = file2urls($file) if ($file); -push @urls, @ARGV; - -my $num = scalar @urls; -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( - ssl_opts => { verify_hostname => 0 }, -); -my $transfer = 0; -my $pm = Parallel::ForkManager->new($concurrency); -$pm->run_on_finish( - sub { - my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $dataref) = @_; - if (defined $dataref) { - $transfer += $$dataref; - } - } -); - -my ($startsec, $startmicro) = gettimeofday(); -for (my $child = 0; $child < $concurrency; $child++) { - use bytes; - if ($pm->start) { - # parent - warn "forks $child/$concurrency child ...\n"; - } - else { - # child - my $transfer = 0; - 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); - if ($res->is_success) { - $transfer += length($res->content); - } - else { - print STDERR "\nfail: $url"; - } - sleep($wait); - } - - $i++; - } - $pm->finish(0, \$transfer); - } -} -$pm->wait_all_children; -my ($endsec, $endmicro) = gettimeofday(); -my $elapsed = ($endsec - $startsec) + ($endmicro - $startmicro) / 10**6; -my $bytepersec = $transfer / $elapsed; - -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", - " OR...\n", - "$0 url1 url2\n" - ; - - exit; -} - -sub file2urls { - my $file = shift; - - open my $fh, '<', $file or die "$file: $!"; - - my(@urls, $url); - while ($url = <$fh>) { - chomp $url; - push @urls, $url; - } - - return @urls; -} -- 1.7.9.5