in reply to How to do parallel processing within mod_perl
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 }
|
|---|