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.


In reply to Re: Stress testing a web server by Aristotle
in thread Stress testing a web server by ibanix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.