distcc is a program that distributes source code among a number of distcc-servers. The distcc-daemon sends parts of the source code to the distcc-servers that compile the code and send back the result to the daemon. This way you can use many machines to compile one program and thus speed up the compilation process. The cool part is you can use it together with pacman/srcpac.
- distcc daemon
- The PC or server that's running distcc to distribute the source code. The daemon itself will compile parts of the source code but will also send other parts to the hosts defined in DISTCC_HOSTS.
- distcc server
- The PC or server compiling the source code it gets from the daemon. When it's done compiling, it sends back the object code (i.e. compiled source code) to the daemon, which in turn sends back some more source code (if there's any left to compile).
First you need to install distcc on every computer you'll be using, on the daemon aswell as the servers. If you're running Arch, it's as easy as doing pacman -S distcc. For other distro's or even OS'es (you can run distcc on a Windows-box using Cygwin!), read the URL distcc docs.
Now that you've got distcc installed, it has to be configured:
On the daemon, edit /etc/makepkg.conf (assuming the daemon is running on Arch) and make sure the BUILDENV has distcc without exclamation mark. For example:
BUILDENV=(fakeroot distcc color !ccache !xdelta)
Change the N in export MAKEFLAGS="-j N" to the amount of CPU's you'll be using + 1. So if you're using three single processor systems, set it to 4. Now uncomment DISTCC_HOSTS
Change serverips in DISTCC_HOSTS=serverips. Where serverips is a list of the IP's of the serving computers you will be using, e.g.:
DISTCC_HOSTS='10.0.1.3 10.0.1.4 10.0.2.75'
If you want to use distcc through SSH, you can add host with "@" symbol in front, i.e. "@10.0.0.3" or "@hostname/2". Set also DISTCC_SSH to ignore checking for authenticated hosts, like:
Edit /etc/conf.d/distccd and add the line
DISTCC_ARGS="--user nobody --allow daemonip"
Change daemonip to the IP of the daemon. If you don't do this, you'll get "connection refused" errors when distcc is trying to send code to the server. By setting the daemonip, you can also make sure your servers won't accept code from other daemons on your network that aren't yours.
Edit /etc/hosts.allow and add the line
Replace 10.0.1. with a comma seperated list of the daemon IP's, or use a notation similar to 10.0.1. to allow a range of IP's: 10.0.1. allow's every IP from 10.0.1.0 to 10.0.1.255 to connect to the server and send it source code. You can also use a CIDR notation: 10.0.1.0/255.255.255.0 is the same as 10.0.1..
If you don't add the above line to /etc/hosts.allow, you'll get error messages like "connection refused" on the daemon, since the server simply won't accept any distccd-connections. Arch's setup is secure by default, remember. ;)
Try it out
Start the distcc daemon on every participating machine (use /etc/rc.d/distccd start). Then put a PKGBUILD you'd like to make a package of on the daemon. Change to the dir of the PKGBUILD and simply run makepkg. Keep an eye on the running processes of the daemon and the servers. When ./configure has finished, and the actual compilation takes place, there should be a significant increase of the processor load as the code is compiled. You can also run tail -f /var/log/messages.log on daemon and server to see what distccd is actually doing.
Remember to add distccd to the list of DAEMONS in /etc/rc.conf on the daemon and servers if you want distcc to be available immediately after a reboot.
Using distcc for every compilation task
If you'd like to use distcc outside of pacman, all you have to do is add the export-lines you added to /etc/makepkg.conf to /etc/profile: the export's in /etc/makepkg.conf are only read on execution of makepkg or makeworld, /etc/profile however is executed on login.