Distcc/ru

Distcc — это программа, предназначенная для распределения по сети задач компиляции в рамках набора хостов. Она состоит из серверной части — distccd и клиентской — distcc. После небольшой настройки distcc может прозрачно работать с ccache, Portage и Automake.

Если вы планируете использовать distcc при начальной сборке (bootstrap) своей установки Gentoo, обратите внимание на раздел Использование Distcc для начальной сборки (bootstrap) Gentoo.

Зависимости
Для работы с distcc все компьютеры в сети должны иметь GCC одной версии. К примеру, можно использовать на разных машинах 3.3.x (где x — разные), а смешивание 3.3.x с 3.2.x может привести к ошибкам при компиляции или выполнении.

Установка distcc
Distcc поставляется с графическим монитором для отслеживания заданий, отправляемых компьютером на компиляцию. Данный монитор включается, когда установлен -флаг.

После настройки  флагов, установите пакет :

Настройка Portage для работы с distcc
Настроить Portage для работы с distcc легко. Выполните следующие шаги на каждой системе, которая должна участвовать в распределенной компиляции:

Сначала удостоверьтесь, что установлен :

Далее установите переменные  и   как показано ниже. Общепринятая стратегия — выбор в качестве  удвоенного числа ядер CPU (локальных + удалённых) + 1, а в качестве   — числа локальных ядер CPU. В случае, если распределенные хосты отсутствуют, либо когда ebuild, который нужно установить требует только локальной компиляции (например, gcc), флаг  предотвращает запуск чрезмерно большого количества заданий.

Например, если два четырехядерных компьютера выполняют distccd, а локальный компьютер имеет двухядерный процессор, то переменная  может выглядеть так:

While editing the file, make sure that it does not have   in the   or   variables. distccd will not distribute work to other machines if  is set to. The appropriate  value can be obtained by running the following command:

See Inlining -march=native for distcc for more information.

Specifying participating hosts
Use the distcc-config command to set the list of hosts.

The following is an example list of host definitions. In most cases, variants of lines 1 and 2 suffice. More information about the syntax used in lines 3 and 4 can be found in the distcc manual page.

There are also several other methods of setting up hosts. See the distcc man page ( man distcc ) for more details.

If compilations should also occur on the local machine, put  in the hosts list. Conversely if the local machine is not to be used to compile, omit it from the hosts list. On a slow machine using localhost may actually slow things down. Make sure to test the settings for performance.

Let's configure distcc</tt> to use the hosts mentioned on the first line in the example:

Edit and be sure to set the   directive to allow only trusted hosts. For added security, use the  directive to tell the distccd</tt> daemon what IP to listen on (for multi-homed systems). More information on distcc</tt> security can be found at Distcc security notes.

Now start the distccd</tt> daemon on all the participating computers:

Setting up distcc to work with automake
This is, in some cases, easier than the Portage setup. All that is needed is to update the  variable to include  in front of the directory that contains gcc</tt>. However, there is a caveat. If ccache</tt> is used, then put the distcc location after the ccache one:

Put this in the user's or equivalent file to have the   set every time the user logs in, or set it globally through an  file.

Instead of calling just make, add in -jN (where  is an integer). The value of  depends on the network and the types of computers that are used to compile. A heuristic approach to the right value is given earlier in this article.

Setting up distcc to work with ssh
Setting up distcc via ssh includes some pitfalls. First, generate an SSH key pair without password setup. Be aware that portage compiles programs as the portage</tt> user. The home folder of the portage</tt> user is, which means the keys need to be stored in

Second, create a section for each host in the SSH configuration file:

Also make sure that each host is available in the file and append the public key to the  file of the hosts. To set up the hosts test1</tt> and test2</tt>, run:

Please note the @</tt> (@ sign), which specifies ssh hosts for distcc.

Cross-compiling
Cross-compiling is using one architecture to build programs for another architecture. This can be as simple as using an Athlon (i686) to build a program for a K6-2 (i586), or using a SPARC to build a program for a PowerPC. This is documented in the DistCC Cross-compiling guide.

Step 1: configure Portage
Boot the new box with a Gentoo Linux LiveCD and follow the installation instructions, while keeping track of the instructions in the Gentoo FAQ for information about bootstrapping). Then configure Portage to use distcc</tt>:

Update the  variable in the installation session as well:

Step 2: getting distcc
Install :

Step 3: setting up distcc
Run distcc-config --install to setup distcc; substitute the  in the example with the IP addresses or hostnames of the participating nodes.

Distcc is now set up to bootstrap! Continue with the proper installation instructions and do not forget to run emerge distcc after running emerge @system. This is to make sure that all of the necessary dependencies are installed.

Some packages don't use distcc
As various packages are installed, users will notice that some of them aren't being distributed (and aren't being built in parallel). This may happen because the package' doesn't support parallel operations, or the maintainer of the ebuild has explicitly disabled parallel operations due to a known problem.

Sometimes distcc</tt> might cause a package to fail to compile. If this happens, please report it.

Mixed GCC versions
If the environment hosts different GCC versions, there will likely be very weird problems. The solution is to make certain all hosts have the same GCC version.

Recent Portage updates have made Portage use  (minus gcc) instead of. This means that if i686 machines are mixed with other types (i386, i586) then the builds will run into troubles. A workaround for this may be to run export CC='gcc' CXX='c++' as root in a terminal, or put it in.

-march=native
Starting with GCC 4.3.0, the compiler supports the  option which turns on CPU auto-detection and optimizations that are worth being enabled on the processor on which GCC is running. This creates a problem when using distcc</tt> because it allows the mixing of code optimized for different processors. For example, running distcc</tt> with  on a system that has an AMD Athlon processor and doing the same on another system that has an Intel Pentium processor will mix code compiled on both processors together.

Heed the following warning:

Чтобы узнать, какие флаги включит GCC при запуске с, выполните следующее:

Distcc monitors
Distcc ships with two monitoring utilities. The text-based monitoring utility is always built and is called distccmon-text</tt>. Running it for the first time can be a bit confusing, but it is really quite easy to use. If the program is run with no parameter it will run just once. However, if it is passed a number it will update every  seconds, where   is the argument that was passed.

The other monitoring utility is only enabled when the    flag is set. This one is GTK+ based, runs in an X environment, and it is quite lovely. For Gentoo, the GUI monitor has been renamed to <tt>distccmon-gui</tt> to make it less confusing (it is originally called <tt>distccmon-gnome</tt>).

To monitor Portage's <tt>distcc</tt> usage:

External resources

 * Inlining -march=native for distcc
 * Distcc homepage