[distcc] Simple autodiscovery of distcc servers

Dan Kegel dank at kegel.com
Thu Aug 11 07:25:24 GMT 2005


Experience seems to indicate that to be practical for wide deployment
in a largish organization, users must be able to use distcc without configuring it.

There are patches to add Rendezvous support to distcc
(see http://www.crocodile.org/lord/DistCCRendezvous.pdf for a writeup),
but being a troglodyte (and more to the point, one without
the power to install zeroconf anywhere), I prefer a simpler approach.

Stop me if you've heard this one before.
This scheme simply requires that distcc servers
have DNS aliases distcc1, distcc2, distcc3, ...

The basic assumption is that an organization will have several sites.
Each site will have its own distcc servers;
no site will use remote distcc servers.
Each site is assumed to have a DNS administrator who is responsive
and willing to add and remove entries for distcc servers
as needed.  This of course limits its usefulness severely,
but when you do have such DNS administrators, it's a good scheme.

The new scheme will be activated when --discover-distccN is given in the hosts list.

The client will discover distcc servers by looking for
hosts named (surprisingly) distcc1, distcc2, distcc3, etc.
It will stop looking when it notices the first distccN
host that doesn't exist in DNS, or which resolves to a different
network number than distcc1.  (This is to prevent accidentally
using the parent domain's servers.)

The results will of course be cached to avoid nasty overhead.

As an illustration, here's a code fragment from a pingdistcc.sh
script I wrote recently that implements part of this scheme.
It uses a compile request for a tiny .c file to check whether
servers are alive.  Presumbly this would be replaced by simply
observing the results of a real compile request when I implement
it for real.

The resulting code change should be quite small, as it will
piggyback on distcc's existing host status cache; very
little new logic should be needed.


function networkOf() {
   host $1 | awk '/address/ {print $4}' | sed 's/\.[0-9]*\.[0-9]*$/.0.0/'
}

# Figure out which hosts we can use
network1=`networkOf distcc1`
   HOSTS=""
   HOSTNUM=1
   announce Searching DNS for distcc1, distcc2, ...
   while true; do
     network=`networkOf distcc$HOSTNUM`
     if [ "$network" != "$network1" ]; then
         break;
     fi
     HOSTS="$HOSTS distcc$HOSTNUM"
     HOSTNUM=`expr $HOSTNUM + 1`
   done

if [ x"$HOSTS" = x ]; then
   abort error: no hosts found?
fi
announce Using hosts $HOSTS

 > $PREFIX.okhosts
for host in $HOSTS; do
    if test x$host = x--randomize; then
       continue
    fi
    DISTCC_HOSTS=$host
    export DISTCC_HOSTS
    (
    echo "int foo(int x) { return x+1; }" > $PREFIX.$host.c
    alarm 5 /usr/bin/time -o $PREFIX.$host.time --format %E $CC -c $PREFIX.$host.c -o $PREFIX.$host.o > $PREFIX.$host.log 2>&1

    if grep -q 'Interrupt' $PREFIX.$host.log; then
       :
    elif grep -q 'failed' $PREFIX.$host.log; then
       announce distcc server $host seems down
    elif test -s $PREFIX.$host.time; then
       announce distcc server $host seems up, latency `cat $PREFIX.$host.time`
       echo $host >> $PREFIX.okhosts
    fi
    ) &
    ALLPIDS="$ALLPIDS $!"
done
wait

-- 
Trying to get a job as a c++ developer?  See http://kegel.com/academy/getting-hired.html


More information about the distcc mailing list