LWP::Simple does blocking requests. The big problem you're facing isn't that some requests take longer than others. It is that whatever length of time they take, your script has to sit and wait before it can proceed to the next request. Since you have no control over how long an individual request can take, you might want to restructure your program around an event loop so that it doesn't have to wait before issuing the next request.

Here is an example of using Mojo::UserAgent and Mojo::IOLoop for non-blocking requests.

use Mojo::UserAgent; use Mojo::IOLoop; my $ua = Mojo::UserAgent->new; # --- Worst nodes -------------------! # --- Best nodes --------------! | # --- Last hour CB -----! | | # \/ \/ \/ foreach my $node ( qw( 596792 9066 9488 ) ) { $ua->get( "http://perlmonks.org/?node_id=$node" => sub { my( $ua, $mojo ) = @_; print $mojo->req->url, " => <<<\n", $mojo->res->text, "\n>>>\n\n\n"; } ); } Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

The point to the exercise is that however many requests you make (within the limits of memory), the IO loop just handles them with the callback you provide as responses come in. Meanwhile, you can continue issuing requests or processing the responses. It's a parallel process, rather than serial.


Dave


In reply to Re: use LWP::Simple slows script down. by davido
in thread use LWP::Simple slows script down. by Jesse Smith

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.