An alternative (since you are working over your own socket layer) would be to use non-blocking sockets.

You could then dispatch your request to each db and select on your socket connections, collecting replies as they come back.

Timeouts fall out of this fairly easily too, but you'll need to be careful if you subsequently re-use a socket and get a response to a timed-out query.

There are various wrappers around this. You can use IO::Socket and IO::Select as a starting point, but there are probably higher-level modules. Anyone else got any ideas?

So something like this:

sub metasearch { my $self = shift; # Note: could make dbs return array in array context # with 'wantarray' my @dbs = @{$self->dbs}; my @db_socks; foreach my $db (@dbs) { my $sock = $db->connect; send_nonblocking_query($sock); push @db_socks, $sock; } my $timeout_at = time() + $timeout_secs; while (@db_socks && time() < $timeout_at) { ..select on @db_socks, timing out at timeout_at ..handle a wakeup on a socket by reading the response } # error handling of remaining @db_socks }

In reply to Re: How to do parallel processing within mod_perl by jbert
in thread How to do parallel processing within mod_perl by Anonymous Monk

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.