Distcc
distcc
On the distcc server, distccd must be run:
distccd --daemon --allow 127.0.0.1 --allow 10.0.0.0/24 --jobs 4
distccd can also be run via inetd:
$ grep distcc /etc/inetd.conf
distcc stream tcp nowait.6000 root /usr/bin/distccd distccd --inetd --allow 127.0.0.1 --allow 10.0.0.0/24 --jobs 4
The clients need to be configured, so that distcc can use their server:
$ cat /etc/distcc/hosts 10.0.0.30 10.0.0.31
Or, to set the distcc server temporarily:
export DISTCC_HOSTS='localhost 10.0.0.30 10.0.0.31'
Build something:
cd ~/some-project-source
make CC=distcc
Note: the server nodes need to provide the same compiler as the distcc client, otherwise the compile jobs might fail with something like this:
distccd[1762] (dcc_execvp) ERROR: failed to exec i686-pc-linux-gnu-gcc: No such file or directory
As a quick (and dirty) solution, a symlink could help:
ln -s /usr/bin/i486-linux-gnu-gcc /usr/bin/i686-pc-linux-gnu-gcc
Another way is to explicitly specify CC='gcc' and CXX='c++'. However, the only sane solution to this is to use the same compiler versions on all the computing nodes.
ccache
To use ccache, simply export the PATH variable to point to ccache wrappers for the compilers:
$ ls -lgo /usr/lib/ccache/bin/ lrwxrwxrwx 1 15 Jan 27 11:56 c++ -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 cc -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 g++ -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 gcc -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 i686-pc-linux-gnu-c++ -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 i686-pc-linux-gnu-g++ -> /usr/bin/ccache lrwxrwxrwx 1 15 Jan 27 11:56 i686-pc-linux-gnu-gcc -> /usr/bin/ccache $ export PATH:/usr/lib/ccache/bin:$PATH
Now every call for e.g. "gcc" will be handled by "ccache". Some other helpful variables:
export CCACHE_DIR="/var/tmp/ccache" ← cache directory export CCACHE_SIZE="2G" ← 2 GB cache export CCACHE_COMPRESS=1 ← compress object files and compiler output
We could also specify the CC variable:
cd ~/some-project-source
make CC="ccache cc"
This way we can combine both distcc and ccache:
make CCACHE_PREFIX=distcc CC="ccache cc"
Display statistics:
$ CCACHE_DIR=/var/tmp/ccache ccache -s [...] files in cache 79583 cache size 645.4 Mbytes max cache size 2.0 Gbytes