You might want to have a look at
LWP::Parallel - something like this:
#!/usr/bin/perl -w
use strict;
use LWP::Parallel::UserAgent;
use HTTP::Request;
my $url = "http://localhost/foo/";
my $pua = LWP::Parallel::UserAgent->new();
$pua->nonblock(1); # accell. connection
$pua->redirect(1); # follow
$pua->max_req(1000); # simultaneous
while(1) {
foreach (0 .. 100) {
my $res = $pua->register(HTTP::Request->new(GET => $url));
die $res->error_as_HTML if $res;
}
$pua->wait(0); # returns hashref
$pua->initialize;
}
and expanding that to report the number of connections:
#!/usr/bin/perl -w
use strict;
# make sure END block is run
BEGIN { SIG{INT} = sub { exit } }
package myPUA;
use Exporter();
use LWP::Parallel::UserAgent qw(:CALLBACK);
our @ISA = qw(LWP::Parallel::UserAgent Exporter);
our @EXPORT = @LWP::Parallel::UserAgent::EXPORT_OK;
our $connections = 0;
sub on_return { ++$connections; return }
package main;
use HTTP::Request;
use Time::HiRes qw(time);
my $url = "http://localhost/foo/";
my $pua = myPUA->new();
$pua->nonblock(1); # accell. connection
$pua->redirect(1); # follow
$pua->max_req(1000); # simultaneous
my $start = time;
while(1) {
foreach (0 .. 100) {
my $res = $pua->register(HTTP::Request->new(GET => $url));
die $res->error_as_HTML if $res;
}
$pua->wait(0); # returns hashref
$pua->initialize;
}
END {
my $sec = time - $start;
print "$myPUA::connections connections in $sec seconds\n";
printf "%.1f conn/s\n", $myPUA::connections / $sec;
}
Most of this is lifted straight out of the module's POD. Took about 25 minutes to write without any real former exposure to
LWP::Parallel.
:) Untested.
Makeshifts last the longest.