distcc, icecream & Incredibuild
A cache helps when the same compile happened before. When it didn't (a new branch, a big refactor, a header everyone includes), the work has to be done, and distributed compilation spreads it over more machines than you have on your desk. None of these tools are installed in this course's image, so the sessions here are sample output; the throughput model at the end is runnable.
distcc
distcc is the classic: a client wrapper (distcc) and a daemon (distccd) on each helper machine.
- The client preprocesses locally (
-E), so the helpers don't need your headers. - It sends the preprocessed source and the command line to a helper.
- The helper compiles it with its compiler and sends back the object file.
- Linking stays local.
# on each helper (allow your subnet)
distccd --daemon --allow 10.0.0.0/24 --jobs 16
# on your machine
export DISTCC_HOSTS="localhost/4 build1/16 build2/16"
cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=distcc
cmake --build build -j 36 # roughly the sum of the slots
distccmon-text 1 # watch which host compiles whatThings that bite:
- Identical compilers everywhere. distcc ships source, not compilers. A different GCC patch level on one helper produces different objects (or ABI bugs). Pin the same compiler package or container image on every machine.
- Local preprocessing is the bottleneck. Your machine still runs the preprocessor for every TU. Pump mode (
pump cmake --build …,DISTCC_HOSTS="build1/16,cpp,lzo") sends headers to the helpers and preprocesses remotely, lifting that limit, but it's finicky with generated headers. - No security. distccd runs any command line it is sent; restrict it to trusted networks (
--allow) or tunnel it over SSH (@hostinDISTCC_HOSTS). - Combine with ccache:
CCACHE_PREFIX=distccmakes ccache call distcc only on misses.
icecream (icecc)
icecream, from SUSE, builds on the same idea with a central scheduler:
iceccdruns on every machine; oneicecc-schedulerassigns each job to the least-loaded node, so a team's idle desktops form one pool.- The client ships its own compiler environment (a tarball made by
icecc-create-env) to helpers that don't have it, so mixed compiler versions are handled. - It can cross-compile for other architectures from the same pool.
icemonshows a live view of who compiles what.
export PATH=/usr/lib/icecc/bin:$PATH # icecc's compiler wrappers first
cmake -S . -B build -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=icecc
cmake --build build -j 64Incredibuild
Incredibuild is a commercial product, strongest on Windows and in game studios: it virtualises the build process so that compiles (and other tasks: shader compilation, tests, asset cooking) run on remote agents while appearing local. It integrates with Visual Studio, MSBuild, Unreal's build tool, CMake/Ninja and Make, and adds a build monitor with a timeline. Licensing is per agent/core; the free tier is limited.
A throughput model
Distributed builds can only go as fast as the slowest stage: local preprocessing, the network, or the remote cores. This model computes the steady-state compiles per second for a 40-core helper pool:
def throughput(local_cores, pre_s, remote_cores, compile_s, pre_kb, mbit, pump=False):
"""Compiles per second through each stage; the pipeline runs at the minimum."""
stages = {
"local preprocessing": float("inf") if pump else local_cores / pre_s,
"network": (mbit * 1000 / 8) / pre_kb,
"remote compiling": remote_cores / compile_s,
}
bottleneck = min(stages, key=stages.get)
return stages[bottleneck], bottleneck
local_cores, pre_s, compile_s, pre_kb = 8, 0.4, 3.0, 1500 # 1.5 MB of preprocessed source per TU
print("local build only: %5.1f TU/s" % (local_cores / (pre_s + compile_s)))
for label, mbit, pump in [("distcc, 1 Gbit/s", 1000, False), ("distcc, 100 Mbit/s", 100, False),
("pump mode, 1 Gbit/s", 1000, True)]:
rate, limit = throughput(local_cores, pre_s, 40, compile_s, pre_kb, mbit, pump)
print(f"{label:<26}{rate:5.1f} TU/s (limited by {limit})")local build only: 2.4 TU/s
distcc, 1 Gbit/s 13.3 TU/s (limited by remote compiling)
distcc, 100 Mbit/s 8.3 TU/s (limited by network)
pump mode, 1 Gbit/s 13.3 TU/s (limited by remote compiling)
With a fast network, 40 remote cores give more than five times the local throughput. On a slow link, shipping 1.5 MB of preprocessed text per TU becomes the limit. Try a larger pool: at some point local preprocessing (20 TU/s here) becomes the bottleneck and pump mode starts to matter. And the link at the end is still local, so the critical path and Amdahl's law still apply.
Test yourself
In distcc's default mode, where does preprocessing happen?
- On the helper
- On the local machine
- On the scheduler
- It's skipped
What does icecream add over plain distcc?
- Caching
- A central scheduler and shipping of compiler environments to helpers
- Linking on helpers
- Windows support
In the model with a 100 Mbit/s link, what limits throughput?
- Remote compiling
- Local preprocessing
- The network
- The linker