Permalink
Browse files

Merge branch 'master' of github.com:shafiev/AnyEvent-HTTPBenchmark

  • Loading branch information...
2 parents 007ec81 + 1083301 commit 239994da356ad2ac2f302426d7cf8b7d788623bd @shafiev committed Jun 12, 2010
Showing with 32 additions and 1 deletion.
  1. +32 −1 benchmark.pl
View
@@ -27,6 +27,28 @@
$AnyEvent::HTTP::set_proxy = $proxy;
$AnyEvent::HTTP::USERAGENT = $useragent;
+# Caching results of AnyEvent::DNS::a
+my $orig_anyeventdnsa = \&AnyEvent::DNS::a;
+my %cache;
+*AnyEvent::DNS::a = sub($$) {
+ my ($domain, $cb) = @_;
+
+ if ($cache{$domain}) {
+ $cb->( @{ $cache{$domain} } );
+ return;
+ }
+
+ $orig_anyeventdnsa->( $domain,
+ sub {
+ $cache{$domain} = [ @_ ];
+ $cb->( @_ );
+ }
+ );
+
+ return;
+};
+# End of caching
+
#on ctrl-c break run the end_bench sub.
$SIG{'INT'} = 'end_bench';
@@ -75,12 +97,16 @@ sub parse_command_line {
"url=s" => \$url,
"n=i" => \$count,
"c=i" => \$concurency,
- "verbose!" => \$verbose,
+ "verbose|v+" => \$verbose,
"debug" => \$DEBUG,
"proxy=s" => \$proxy,
"useragent=s" => \$useragent
);
+ if ($concurency > $count) {
+ $concurency = $count;
+ }
+
unless ($url) {
if (@ARGV) {
$url = shift @ARGV;
@@ -105,6 +131,11 @@ sub add_request {
push @reqs_time, $req_time;
$done++;
+ if ($verbose >= 2) {
+ print "=========== HTTP RESPONCE ===========\n";
+ print @_[0];
+ }
+
my $hdr = @_[1];
if ( $hdr->{Status} =~ /^2/ ) {

0 comments on commit 239994d

Please sign in to comment.