How does the number of bananas get updated on the nodes? Is there any calculation going on on the nodes - or just a summing of the bananas? How often do the numbers change? Do you know the number of bananas at the time the number changes?
You may be lucky enough to be able to write out a static HTML page containing the number of bananas. Nothing will be able to query as fast as this.
But even if you do have to use a cgi script or mod_perl (I'd heavily suggest mod_perl), the following algorithm will work fine - and there is no threading or forking.
my @socks;
for my $host (@hosts) {
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => 80);
die "$host failed: $!" if ! $sock;
print $sock "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
push @socks, $sock;
}
my $sum = 0;
for my $sock (@socks)
local $/ = '';
my $resp = <$sock>
$sum += parse_resp($resp);
}
This code works and is as fast as your slowest server because: You have asked all of the servers the question which takes near 0 time (assuming connection time isn't the issue). Each of the servers can take however long they need to generate the response. Then you begin asking for the answers. As long as the transport isn't an issue (on a local network it better not be), then you basically asked all of the servers for the answer and got the results back in about the time that it took for the slowest server to generate the response. Servers that get done more quickly simply have the result waiting for you in the open $sock handles. Ones that take longer will block while you read $sock - but that is OK because other servers will still be creating their responses while you wait for the slow one.
You can try things more complicated - but chances are very, VERY high that the extra complication will introduce its own overhead and bottlenecks and won't deliver the results any faster. (If connection time or transport are issues then all of this goes out the window - but it is doubtful connection or transport will be the bottleneck for this application).
my @a=qw(random brilliant braindead); print $a[rand(@a)];