Reduce C/C++ Compile Time With distcc
An anonymous reader writes "Some people prefer the convenience of pre-compiled binaries in the form of RPMs or other such installer methods. But this can be a false economy, especially with programs that are used frequently: precompiled binaries will never run as quickly as those compiled with the right optimizations for your own machine. If you use a distributed compiler, you get the best of both worlds: fast compile and faster apps. This article shows you the benifits of using distcc, a distributed C compiler based on gcc, that gives you significant productivity gains."
While distCC is a great tool, there are a couple things to mention. First, the article blurb states that distCC is "a distributed compiler based on GCC." It is actually a method of passing files to GCC on a remote computer in such a way that the build scripts think it was done locally.
The article also says that other than distCC, the computers need not have anything in common; this is not strictly true. Different major versions of GCC can cause problems if you are trying to compile with optimization flags that are only on the newer version. I have run into this on my gentoo box, trying to use an outdated version of GCC on a redhat box.
Another thing is that some very large packages have trouble with distributed building of any sort (either multiple threads on the same machine, or over a network like with distCC). As far as I know, at least parts of xfree86, KDE and the kernel turn off distributed compiling during the build. Some of this might just be in the gentoo ebuilds, but I tink some of it is in the actual Makefiles. If a program has trouble compiling, it's always worth a shot to turn off distCC.
A good resource for setting up distCC on a gentoo system (since compiling is so large of gentoo, this is particularly important) is gentoo.org's own distCC guide
It's also been been discussed here on Slashdot (two years ago!) in "A Distributed Front-end for GCC" and earlier this year in "Optimizing distcc."
Distcc is great for installing Gentoo on an older computer because you can have other (faster) computers help with the compile, and if you like distcc, you may also like ccache.
That's why I use Gentoo!
Now one can install Gentoo in _only_ 5 days!
I think nc can be used like distcc by redefining CC="nc gcc". However, more commonly it is done by putting $(NC) at the beginning of the build rules. Then you can use nc for any build rules, not just C compiles.
In addition to use with make, nc works well with SCons.
I just installed a second Gentoo box, a lowly Pentium 2 400mhz with 128mb RAM and read up on distcc. It certainly makes compiling Gentoo a LOT faster when the otherwise poor underpowered box can ask my AthlonXP 2400 for some compiling help.
It also requires rather minimal configuratio on my part and for the most part "Just Works[tm]"
Hehe.. now if only I had a beowolf cluster....
My family can't afford more than one computer, you insensitive clod!
But seriously, is there a way to make use of the concepts embodied in distcc in a home computing environment? Or is distcc designed for use by for businesses and schools?
Any application I have to compile before using with the 'correct optimizations for my machine' will take more time to get up and running than any 'productivity gains' it might produce. This is why Linux is still not accepted by mainstream computer users. They don't care how it works, just that it does.
Compare the speed cost of loading a "generic" binary to an "optimised" one, multiply by the number of times you load that binary.
Then look at the time required to compile the optimised copy.
How often, in the lifetime of a particular version of a binary, do you really need to reload it?
The promise of distcc is closely related to source distributions like Gentoo. The benefit is overstated. Don't waste your time.
Quick wafting zephyrs vex bold Jim
Personally, I think that distcc will become more and more useless as computers get faster. My new machine (P4 2.8, 1 GB RAM, SATA drives) can compile a complete Gentoo desktop system in just about two hours. That's pretty damn cool considering that it used to take like 24 on my old laptop when I first started using Gentoo several years ago. It would probably only take about an hour to setup a server system on Gentoo on my same machine since the biggest component, X, would not need to be compiled.
Computing power is outstripping the size of source code that needs to be compiled. Soon there will be little difference in install time between the source and binary distros, and all the jokes about Gentoo's compile time will be pretty much obsolete. Already, once you have your system installed, the time required to keep current/install new apps is minimal. My system can compile any new program (except maybe OpenOffice) in under 25 minutes. Even Mozilla can be compiled in that time.
Well, as someone who recompiles FreeBSD/DragonFly quite frequently, I've got to say that the best way to reduce the time it takes is to build eveything in a ramdisk. I've cut 100 minute compile times down to about half an hour by mounting /usr/obj in a ramdisk instead of on my hard drive.
r tid=53
http://bsdvault.net/sections.php?op=viewarticle&a
We use the distcc that Apple distributes with XCode even though we dont' use XCode itself. It really helps to get a few dual-CPU G5's working!
The cool thing about Apple's version is that by default it uses Rendezvous to determine which machines are available to distribute work to.
Reducing compile time by distributing the load isn't reducing it all, it's just distributing it. Try using a compiler that compiles fast -- such as Plan 9s compilers.
Which makes it a pain in the ass if you ask me.
I have tried to use distcc for a lot of stuff, but it doesn't work on some packages, and that's enough to make me not use it.
I don't want to have to hand-pick which packages to use it with and which ones to not use it with. Fortunately, a lot of Gentoo packages have a rule built in to not use distcc automatically, but it's not always the case.
The other thing about distcc is that it won't increase the speed of the compile by any large magnitude with each machine added because the machine performing the actual compile has to do a lot more work then the slaves.
Unless I was trying to compile something on a REALLY slow machine, I don't bother with distcc.
- It's not the Macs I hate. It's Digg users. -
Precompiled binaries will never run as quickly as those compiled with the right optimizations for your own machine
And there are maybe about ten to fifteen people on all of slashdot who actually know how to go about setting the right optimizations for their own machine.
"(...) a distributed C compiler based on gcc, that gives you significant productivity gains."
Assuming
a) That compiling will give you any significant performance increase (which I kinda doubt, it's not like the defaults are braindead either)
b) You don't spend more time mucking about with distCC / compiling than you'll actually use the software
c) Your software is actually code bound (and not "What do I type/click now?" human bound, or bandwidth bound or whatever)
I can't think of a single thing I do that's code bound. And I actually do a bit of compiling, but I spend those seconds thinking about what to code next. Either that, or it is bandwidth bound or non-time critical (i.e. does it take 6,5 hours or 7 hours? Who cares. The difference is half an hours work for my computer, 0 for me. So the time I'd spend to improve it is - gasp - 0.
Kjella
Live today, because you never know what tomorrow brings
It's news to people that don't read slashdot every day.
I don't mind revisiting older topics once in awhile - it's only annoying when it's two days in a row. And even then, it's not that big of a deal, I simply pass over it.
Posts like this are more waste of space then then a duplicate article post, and you get a lot more posts like yours then we do dupes. It's especially annoying when people say "We talked about this TWO YEARS AGO!!!" Well here's some news for you: I don't memorize every slashdot story since the beginning, and there's been a lot of new members since then.
- It's not the Macs I hate. It's Digg users. -
Other then distributed compiler tools like distcc and nc are there any other ways of speeding up a linux compile with gcc?
I was blown away when my project group compiled a Qt app that we developed on the Linux platform with the MS VC++ compiler. The compilation took 1/10th the time! We were using Makefiles generated by QMake in both cases.
Should I just switch compilers? If so does anyone have any suggestions?
The problem with compiling your own binaries is that you are effectively forking code from the original distribution at the low level. To do this you really must know what you're doing, and that can be a very difficult thing when working with applications you didn't write yourself.
Just look at the Linux Kernel Mailing List and how many errors can be traced to a GCC specific version. That's why Linus enforces a standardized compiler environment, developers can't be wasting their time fixing compiler-induced errors.
I know it's attractive to just recompile your whole distribution to your specific hardware combination because there are real world performance gains, but sometimes there are weird bugs caused by it and you'll probably be out of luck trying to find some documentation on them. What are the chances of somebody having the same hardware configuration? And remember we're not talking about branded components and specific models, we must throw in firmware, drivers, BIOS settings and whatnot into the mix.
As long as the PC components are not standardized, this problem is never going to be away. I seriously considered Mandrake and Gentoo a couple of times in the past and they had very different bugs on each version every time I tried them. Even though they have gotten better on each release, I'd still refuse to put them on a production machine, there's a reason why every distro ships with a precompiled i386 kernel.
I, for one, just recompile the most important parts of a system that do require most of the CPU time, like the kernel, Apache, and other runtime libraries whenever I do need that extra punch, not a second before. distcc is a geek tool and has that coolness-factor and all, but I'm not on a frenzy to use it to recompile all my servers' software, I care about stability first.
- Otaku no naka no otaku, otaking da!!!
O2 is your best all-around setting. Os does make smaller code, but the stuff it outputs is slower. It also causes weird problems with certain apps. It could be useful to condense the memory footprint of properly designed code (like GlibC.) But remember, decreased memory footprint=more hoops the computer has to go through. Think of it like employing fold out-tables. Sure it saves space, but you spend time folding it and unfolding it.
O3 is a waste of time, except for certain scientific computing apps, or apps where you don't mind blowing out your memory for the sake of speed (i.e. games).
"Learning is not compulsory... neither is survival."
--Dr.W.Edwards Deming
Honest question: gcc has the reputation of not producing the fastest code for x86, so why should I bother compiling gentoo with gcc or distcc?
Does anyone know if there are distro's compiled with, say, the Intel compiler?
While I haven't RTFA yet, I find the premise stated in the posting somewhat far-fetched. If I need binaries tuned finer than those provided by binary .rpm's, I can take their respective .src.rpm's and rebuild them. The RPM build system, in the distributions I know, provides a convenient way to override optimization flags via system- or user-settable macros. As for compilation time, it's not an issue for most packages these days, as many Gentoo users here can testify.
My exception safety is -fno-exceptions.
I've got two Gentoo systems that run distccd.
I did some non-scientific testing with distcc.
System one:
Athalon 1400 XP
512 Meg RAM
System two:
Pentium III 450
512 Meg RAM
I compiled GAIM on System one with distccd running on system one and two, also compiled with just distccd running on system one.
I found that with both systems running distccd I got about a two minute faster compile. Then with just distccd running on system one.
With distccd running on just system one I found that it would process many of the individual compiles in parallel ah-la SMP, thing is it's a single processor system. I've not tested the time on system one of distccd vs no distccd. I imagine that with the parallel compiles it works faster. It all depends on what you set your -jN to, where N is the number of "systems" X2 +1. I found that with two systems I could run well with a -j of 7. A bit higher then suggested.
It is correct that many programs that have sensitive builds, XFree and Opera for example, it turns off the -j option. Not a big deal, just means a longer coffee break.
Distccd has come in very handy when I was installing Gentoo on an old Gateway 2100 Solo laptop. The laptop only has a Pentium 120 and 40 Megs of memory.
I'd suggest distcc for anyone who does quite a bit of source builds, a must for a Gentoo install!
--All programmers are playwrights and all computers are lousy actors.
Just last weekend I set up distcc via cygwin on 3 PCs to help my Gentoo box compile. Unfortunately, I wasn't able to successfully compile the cross compiler under cygwin, so I used a pre-built version, available under the Gentoo forums thread linked below. It seems to work well so far, although the Windows boxes are definitely slower than equivalent Linux boxes. But as they are not my computers to begin with, I won't be complaining anytime soon ;)
Gentoo has a HOWTO entitled:
"HOWTO: Use a Windows box as a distcc server for linux."
http://forums.gentoo.org/viewtopic.php?t=66930
The Anti-Gentoo zealots always say stuff like "It's not going to be faster.." etc etc..
:P
Now someone is saying: "precompiled binaries will never run as quickly as those compiled with the right optimizations for your own machine."
So, the Gentoo users that are claiming that stuff compiled with the right optimizations *is* faster?
I'm confused. Which is it supposed to be? Are Gentoo users full of crap, or are they correct?
I use Gentoo and have found things to be a hell of a lot easier to deal with than RPM based binary distros anyway.
I just want the scoop.
Oh, distcc has been in Gentoo for a while.. surprised to see it listed like it's a new thing.
I've spent the last week setting up a Gentoo cluster with distcc and I've noticed a few things:
1. when *recompiling*, the advantage due to ccache far outweighs the performance of distcc on the first compile. If you're testing distcc you need to be aware of this and disable ccache.
2. most large packages either disable distcc (e.g. xfree by limiting make -jX) or compile small sets of files in bursts and spend the majority of time performing non-compilation and linking. Distcc helps with the compilation but because it's only a small part of the total build time, the overall improvement isn't as great as you might have hoped.
3. distccmon-gnome is very cool.
4. using distcc with Gentoo transparently involves modifying your path and this can make non-root compilations troublesome (permissions on distcc lock files). I haven't figured this one out yet other than to specify the full path to the compiler: make CC=/usr/bin/gcc rather than CC=gcc.
5. the returns from adding an extra distcc server to the pool drop considerably after the first few machines. Even on a 1 gigabit LAN the costs of distcc catch up with the benefits after a while. This is more of a concern when compiling lots of small files.
6. it can handle cross-compilation with a bit of configuration.
So although distcc can often reduce build time, it's not quite as effective as you might assume or hope at first.
If you fell sad, alone. If you think you are wasting your youth in many lonely nights, then compiling your Gentoo distribution with dedicated and optimizing flags may suit you.
precompiled binaries will never run as quickly as those compiled with the right optimizations for your own machine
A straw man. Precompiled binaries may have been compiled with the optimal settings for your machine, and binaries which you compile may not have the optimal settings. Identifying the optimal settings can actually be non-trivial. Source-based distributions are not necessarily the best fix to the 'one-size-fits-all' approach used by some distro's.
I came across distcc by chance about 4 months ago, and I must say, it has utterly improved things around here.
:-( ).
We reguarly develop/compile/debug a moderate-small sized software package, typically taking about 1 minute per compile. Now, while 1 minute doesn't sound like a long time, it starts adding up when you find yourself recompiling 100+ times a day.
With the inclusion of distcc into the whole situation, we're able to reduce that 1 minute compile down to a little less than 20 seconds; highly appreciated (although now we have less excuses to go get a coffee
Distcc is a great package which can be extremely useful.
PLD.
While it is slightly different in concept, check out ccache. It only uses a single computer but it can significantly speed up your compiles. It works by caching the results of each compilation; it will only help if you compile the same code over and over.
But this can be a false economy...
Every time something that is distributed in binary is rebuilt from source for local use, by definition it's to change some assumption that was inherent in the testing of the original binary (or else the binary distribution would suffice). And with that, some non-0 confidence that was built into the binary release by that testing is wiped out and must be recovered by local analysis and testing (i.e., time and effort) or reduced expectations. Otherwise, it's running on blind faith. This is particularly true with programs that are used frequently, i.e., one expects to depend on them repeatedly. So in my mind, "the best of both worlds" is more meaningful if it refers to fast and reliable apps. I don't care how fast the compiler is if I can't trust the results anymore. That is a different economy equation, and completely justifes the "convenience" of pre-compiled binaries in many applications.
My main use for distcc currently is building software for my powerbook.
I do a lot of work with Qt on both Linux and Mac, and lets just say Qt compiles very slow on my powerbook (which is an older 800 mhz G4).
Also, I've had to build all of Qt on this machine because the fink packages are old and don't even use the Mac version (they use the X11 version which really sucks and makes apps on Macs look like crap).
So at work we have a couple dual G5s I use, and also a few Linux machines which I've built darwin cross-compilers for (yes its a pain in the ass).
I remember compiling 2.0.x kernels on my own 100MHz Pentium. It took -forever-.
Later on, I built a 350MHz K6-2 machine for a customer, and it was a screamer compiling its 2.0.x kernel, taking just a few minutes.
Fast forward: I've got a very similar K6-2 350 as a miscellaneous server and firewall here. Compiling its 2.6 kernel takes -forever-.
But the new 2.4GHz HT 800MHz FSB P4 box I built recently for work is again a screamer, compiling its 2.6 kernel in a few minutes. This box is in roughly the same relative performance league as that K6-2 was Back In The Day.
Moral of this story: The more things change, the more they stay the same. Program and compiler complexity has kept pace with increases in processor speed, leaving the time to compile x more or less constant over at least the past few years.
'Sides, even if you can build a proper desktop system in two hours, distcc serves well to decimate the amount of time required. Whether it is used to cut that two-hour-long run down to 30 minutes minutes, or a 5-minute compile down to 60 seconds, distcc will always have its place[1].
[1]: Yes, yes, I know. People everywhere are saying "But who cares if it takes 5 minutes instead of 60 seconds? It's not like I can't continue using the machine while it's compiling." These people are ignoring the human aspect of the whole thing, which can be summarized as follows: Wife, house, kids, cars, jobs = 4 minutes worth of life that has been rescued from the computer by distcc.
Kid-proof tablet..
At the moment there's a bug in Linux kernel 2.4.26 that causes the remote compiling systems to encounter a kernel panic (and crash.)
It's a known bug and has been discussed on the lkml. The bug is also discussed on the gentoo bugzilla. A patch is also available, though the patch program didn't work for me so I had to apply it manually.
The patch seems to be holding up, too. If you're using distcc on systems with vanilla 2.4.26 kernels, I'd suggest patching them.
-kidlinux.
It's so PAINFULLY SLOW to build anything for the Mac, with this inefficient Objective-C compiler and large linking requirements for Carbon, that without these distributed tools and some G5 servers, it would be hard for us to develop.
Interestingly, our Windows version of this product, built in C#, compiles extremely fast with no distributed trickery needed.
For those using Visual Studio on Windows, I highly recommend a tool called Incredibuild to do the same job. It is not free like distcc, but is very effective and integrates nicely with Visual Studio. It cut my build time for a project at work from 15 minutes to 1 minute 20 seconds. Nice!
kingos
The claim also contains the assumption that applications are CPU-bound. All the recompiling in the world won't make something go faster if it's waiting on a disk or a UART or a NIC. Many applications are fast enough anyway -- who cares if /bin/cat gets a 2% improvement of its CPU use? I bet I could add a 20 microsecond gratuitous delay in the main loop of cat, and not noticably affect its performance!
That said, the kinds of things I would like to have extra-optimized for speed are generally big, huge, complicated things that take forever to compile. Like an Xserver. And that's definitely where distcc could come in handy.
... was just released.
Only available on mirrors, currently.
Belief is the currency of delusion.
Many programs that can use the SSE or MMX extensions (such as video codecs or Software OpenGL) will fail to compile with DistCC, reporting "Couldn't find a register of class BREG".
If the failing package is one of many, you can emerge just the one package by changing make.conf FEATURES to not include distcc.
Note here I've used the ccache feature. It's really handy because it won't re-compile any parts that've already compiled sucessfully. When make quits on an error, emerge cleans out the sandbox so you can't just let make take care of the already compiled objects.While I've come across your argument a lot, regarding lots of little amounts of saved time, I struggle to see any actual value in these "micro" time savings.
How do you collect up all these micro time savings, making up an "new" hour, in which you can usefully do something else ?
The only application you've mentioned where I think these optimisations matter is DVD encoding. More broadly, useful time savings can be gained as these jobs tend to take a lot of time eg. I would consider saving 5 minutes on an hours video processing to be worth it. 5 seconds saving per hour wouldn't be.
I don't see how reducing an SSH connection set up time by 0.25 of a second is going to make me dramatically more productive, even if I do it 1000 times a day. 1000 * 0.25 = 250 seconds, or just over four minutes a day saving. I spend more time in the toilet than that, maybe I should start taking my computer to the toilet with me ?
My point is this - you need to do a cost benefit analysis, to determine whether the actual time saving has any useful value. In a lot of cases, on the typical, relatively high-performance machine, across the board CPU optimisations don't have any useful value.
I think throwing away your TV set would be far more productive than compiling everything from source in most cases.
The Internet's nature is peer to peer - 20050301_cs_profs.pdf
Heh. No. GCC pretty regularly breaks binary compatibility for the C++ ABI. Breaks were at GCC 2.95 -> 2.96 (though 2.96 was just a RH/Mandrake thing), 2.x -> 3.0, 3.1 -> 3.2 and 3.3 -> 3.4.
You can't mix C++ compiled with any of the compilers that are on opposite sides of those splits.
Wrong again. Both KDE and the Linux kernel build fine with distributed compilation systems. In fact, KDE has been used with distcc and TeamBuilder for years (TB has been used at the last several KDE meetings) and now there's even IceCream (developed by KDE folks) in KDE's CVS which is sort of based on distcc, but has a central scheduler and does better automatic configuration. It also gets around the first issue above because it's able to build a basic runtime environment based on your system tools (compiler, glibc, etc.) and ship it over to the host machines to build in a chroot environment.
The kernel also works just fine in a distributed build environment; I build it regularly with such.
Worryingly the article does not mention *at all* the obvious security questions. If you run a distcc service on a host then who is authorized to connect to it and compile programs? How do they authenticate? What about protection against man-in-the-middle attacks (you may not be paranoid enough to worry about people fiddling with the object code before it is sent back, but at least you ought to know if it's possible). I hope it's not another case of 'ignore security in the service, but it's okay, we'll just put it behind a firewall'.
FWIW, distributed compliation programs like distcc are a good reason to check for buffer overruns and other memory trampling in the compiler. If you've ever managed to segfault gcc by feeding it a bad piece of code, there is a potential exploit via distcc if you can craft a C program that makes the compiler misbehave in the way you want.
-- Ed Avis ed@membled.com
Xcode build system: Distributing Builds Among Multiple Computers
Yes, Apple has come standard with distcc for quite some time.
“Common sense is not so common.” — Voltaire