I have a working piece of code which performs a series of HTTP GET requests within a second. I am using LWP::Simple module to perform the GET requests and the Time::HiRes to pause for a fraction of a second between requests. The baseline time it takes to perform a GET request to a certain server is 0.06 sec (or 60,000 msec), so i deduced that in order to perform 10 requests a second i must sleep for 0.04 seconds (Actually, to account for any errors I rounded down the sleeping time to 0.03 sec).

The reason I am posting this is to ask if anyone knows of a better or more efficient way to produce a script that "pounds" a server at 'x' times per second.

Thank You very much,

jcr

here is the code:

use LWP::Simple; use Time::HiRes qw(usleep); open(URL_LIST, 'url_list.txt') || die "Cannot open: 'url_list'\n$!\n"; while(<URL_LIST>) { chomp; get($_); usleep('0.03'); } close(URL_LIST);

In reply to Efficiently send GET requests under a second by jcr

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.