in reply to Rapid inter-machine communication on internal network

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)];

Replies are listed 'Best First'.
Re^2: Rapid inter-machine communication on internal network
by Anonymous Monk on Oct 31, 2006 at 19:18 UTC
    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?

    The cost for a worker node to figure out how many bananas it has is next to nothing. So the nodes will be able to answer back on the first loop right away.

    The cost for a worker node to figure out how much it should charge for a banana varies. It can be small; it can be quite substantial. There calculation is very complex.

    Updates are potentially very frequent, and we have to plan as if they are occurring all the time.

    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).

    This is cool, though the web-page thing won't work out. However, these apps are all persistent, and from what I gather we can establish enduring socket connections between them. So we can iterate over an array of existing connections instead of hostnames. Your point about blocking still applies. The amount of data transmitted between boss and worker nodes is small, so transmission time won't be an issue unless some unknown factor gets in the way and interferes with a connection. From what I read in this thread, I gather no such problem is likely to arise at the level of the internal network when using sockets (assuming that we're nowhere near network capacity).

    We still need to handle the case of individual worker nodes malfunctioning, but since the first loop has a tiny cost, it can also serves as verification that everybody's present and accounted for.