#!/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; }