Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add basic command line args

  • Loading branch information...
commit 51ccfdd4316cbf8784d81fa84ad0335c1af0d1de 1 parent e246012
@shafiev authored
Showing with 35 additions and 19 deletions.
  1. +1 −4 Version
  2. +34 −15 benchmark.pl
View
5 Version
@@ -1,4 +1 @@
-Ver : 0.02
- -add some stats output + small code refactoring
-Ver : 0.01
- -first public release
+0.03 released at 8.12.2009
View
49 benchmark.pl
@@ -1,36 +1,46 @@
#!/usr/bin/env perl
#Yet another http benchmark ;)
-use common::sense;
-use AnyEvent::HTTP;
-use Time::HiRes;
-use Getopt::Long;
-use DateTime;
-use Data::Dumper;
+use common::sense; #new features
+use AnyEvent::HTTP; # main module
+use Time::HiRes; # to measure time
+use Getopt::Long; # to command line parsing
+use DateTime; # to make time human-readable :)
+use Data::Dumper; # to see the date in debug
my $DEBUG = 0; #Debug mode. Default is false (0)
-my $timeout = 60;
+my $timeout = 60;
my $count = 30000; #number of requests
my $concurency = 20; # number of parralle requests
my $done = 0;
-my $url = 'http://elementa.su/';# url to test
+my $url = 'http://elementa.su/';# default url to test
my $method = 'GET'; #http method
+my $proxy; # proxy server
+my $file; #scenario file
+my $max_recurse = 10; # the default recurse number;
+my $useragent = 'Mozilla/5.0 (compatible; U; AnyEvent::HTTPBenchmark/0.03; +http://github.com/shafiev/AnyEvent-HTTPBenchmark)';
-my $cv = AnyEvent->condvar;
#arrays
my @reqs_time; # the times of requests
my @scenario; #used for script scenario file . Not yet implemented (:
+parse_command_line(); #parsing the command line arguments
+#read_script_file(); #read the url script file
+
$AnyEvent::VERBOSE = 10 if $DEBUG;
$AnyEvent::HTTP::MAX_PER_HOST = $concurency;
+$AnyEvent::HTTP::set_proxy = $proxy;
+$AnyEvent::HTTP::set_proxy = $max_recurse;
+$AnyEvent::HTTP::USERAGENT = $useragent;
#on ctrl-c break run the end_bench sub.
$SIG{'INT'} = 'end_bench';
+my $cv = AnyEvent->condvar;
+
+#start measuring time
my $start_time = Time::HiRes::time;
my $dt = DateTime->from_epoch( epoch => $start_time );
say 'Started at ' .($dt->hms). '.' .($dt->millisecond);
-#read_script_file(); #read the url script file
-
#starting requests
for ( 1 .. $concurency )
{
@@ -41,6 +51,18 @@
end_bench(); # call the end
#subs
+sub parse_command_line
+{
+ #get options which ovveride the default values
+ my $result = GetOptions ("url=s" => \$url,
+ "n=i" => \$count,
+ "c=i" => \$concurency,
+ "debug" => \$DEBUG,
+ "file=s" => \$file,
+ "proxy=s" => \$proxy,
+ "useragent=s" => \$useragent );
+}
+
sub add_request
{
my ($id, $url) = @_;
@@ -75,9 +97,7 @@ sub add_request
#sub read_script_file under test
sub read_script_file
{
- my $file = $ARGV[0];
-
- warn "invalid file "
+ die "invalid file "
unless -e $file and -s _ and -f _;
@@ -101,7 +121,6 @@ sub read_script_file
}
-
sub end_bench
{
my $end_time = Time::HiRes::time;
Please sign in to comment.
Something went wrong with that request. Please try again.