Distcc

提供: ArchWiki
2015年1月9日 (金) 23:19時点におけるKusakata (トーク | 投稿記録)による版
ナビゲーションに移動 検索に移動

関連記事

Distcc は C, C++, Objective C, Objective C++ のコードのビルドをネットワーク上の複数のマシンに分散させるプログラムです。distcc は常にローカルビルドと同じ結果を生成し、インストールと使用方法がシンプルで、ローカルコンパイルよりもずっと高速です。pacman/srcpac と一緒に使うことができます。

用語

ノート: このソフトウェアでは、distcc クラスタの"デーモン"がマスター、"サーバー"がスレーブ PC と、やや直感に反した使われ方がされています。
distcc デーモン
ソースコードを分散させるために distcc が動く PC もしくはサーバー。デーモン自身もソースコードの一部をコンパイルしますが、DISTCC_HOSTS で定義されたホストに他の部分を送信します。
distcc サーバー
デーモンから受け取ったソースコードをコンパイルする PC もしくはサーバー。コンパイルが完了したら、デーモンにオブジェクトコード (つまりコンパイルされたソースコード) を送り返します。そして (まだコンパイルするべきソースコードが残っている場合は) さらにソースコードが送信されてきます。

インストール

公式リポジトリからクラスタの PC 全てに distcc パッケージをインストールしてください。

他のディストロや、Cygwin を使用する Windows など他の OS を使う場合は、distcc のドキュメント を参照してください。

設定

デーモンとサーバー

/etc/conf.d/distccd を編集してアンコメントされた行だけを適当な IP アドレス、デーモンの範囲またはサブネット全体に変更してください:

DISTCC_ARGS="--user nobody --allow 127.0.0.1 --allow 192.168.0.0/24"

デーモンのみ

/etc/makepkg.conf の以下の3つのセクションを編集してください:

  1. BUILDENV で distcc の前のエクスクラメーションポイントを外して有効にしてください。
  2. DISTCC_HOSTS 行をアンコメントして、サーバー(スレーブ)の IP アドレスとスラッシュ、使用するスレッドの数を追加してください。後ろの IP アドレスとスレッドは空白で区切ります。リストは一番強力なサーバーから非力なサーバーの順で並べます (処理能力)。
  3. MAKEFLAGS 変数を個々のサーバーの最大スレッド数をすべて合計した数字にしてください。下の例の場合、5+3+3=11 になります。合計数以上を指定した場合、余った論理スレッドは distcc によってブロックされ、下で説明している distccmon-text などの監視ユーティリティでそのように表示されます。
ノート: It is common practice to define the number of threads as the number of physical core+hyperhtreaded cores (if they exist) plus 1. Do this on a per-server basis, NOT in the MAKEFLAGS!

例:

BUILDENV=(distcc fakeroot color !ccache !check)
MAKEFLAGS="-j11"
DISTCC_HOSTS="192.168.0.2/5 192.168.0.3/3 192.168.0.4/3"

SSH を通して distcc を使いたい場合、セクションの IP アドレスの前に "@" シンボルを追加してください。キーベースの認証をセットアップしていないときは、認証済みのホストのチェックを無視するように DISTCC_SSH 変数を設定してください: DISTCC_SSH="ssh -i"

コンパイル

参加する全てのマシンで distcc デーモンを起動してください:

# systemctl start distccd

ブート時に distccd を起動させるには、参加するマシンで次のコマンドを実行してください:

# systemctl enable distccd

通常通り makepkg でコンパイルしてください。

進捗を見る

複数の方法で進行状況を確認することができます。

  1. distccmon-text
  2. ログファイルを tail で表示する

distccmon-text を実行してコンパイル状況をチェックします:

$ distccmon-text
29291 Preprocess  probe_64.c                                 192.168.0.2[0]
30954 Compile     apic_noop.c                                192.168.0.2[0]
30932 Preprocess  kfifo.c                                    192.168.0.2[0]
30919 Compile     blk-core.c                                 192.168.0.2[1]
30969 Compile     i915_gem_debug.c                           192.168.0.2[3]
30444 Compile     block_dev.c                                192.168.0.3[1]
30904 Compile     compat.c                                   192.168.0.3[2]
30891 Compile     hugetlb.c                                  192.168.0.3[3]
30458 Compile     catalog.c                                  192.168.0.4[0]
30496 Compile     ulpqueue.c                                 192.168.0.4[2]
30506 Compile     alloc.c                                    192.168.0.4[0]

プログラムを持続的に実行させるには、watch を使うか、コマンドに空白と繰り返す待機秒数を加えます:

$ watch distccmon-text

または

$ distccmon-text 2

デーモンで /var/log/messages.log を tail することもできます:

# tail -f /var/log/messages.log

Distcc で "クロスコンパイル"

There are currently two method from which to select to have the ability of distcc distribution of tasks over a cluster building i686 packages from a native x86_64 environment. Neither is ideal, but to date, there are the only two methods documented on the wiki.

An ideal setup is one that uses the unmodified ARCH packages for distccd running only once one each node regardless of building from the native environment or from within a chroot AND one that works with makepkg. Again, this Utopian setup is not currently known.

A discussion thread has been started on the topic; feel free to contribute.

Chroot を使う方法 (推奨)

ノート: This method works, but is not very elegant requiring duplication of distccd on all nodes AND need to have a 32-bit chroots on all nodes.

Assuming the user has a 32-bit chroot setup and configured on each node of the distcc cluster, the strategy is to have two separate instances of distccd running on different ports on each node -- one runs in the native x86_64 environment and the other in the x86 chroot on a modified port. Start makepkg via a schroot command invoking makepkg.

i686 chroot の DISTCC_HOSTS にポート番号を追加する

Append the port number defined eariler (3692) to each of the hosts in /opt/arch32/etc/makepkg.conf as follows:

DISTCC_HOSTS="192.168.1.101/5:3692 192.168.1.102/5:3692 192.168.1.103/3:3692"
ノート: This only needs to be setup on the "master" i686 chroot. Where "master" is defined as the one from which the compilation will take place.

ネイティブ環境から makepkg を呼び出す

Setup schroot on the native x86_64 environment. Invoke makepkg to build an i686 package from the native x86_64 environment, simply by:

$ schroot -p -- makepkg -src

Multilib GCC を使う方法 (非推奨)

警告: Errors have been reported when using this method to build the i686 linux package from a native x86_64 system! The chroot method is preferred and has been verified to work building the kernel packages.

/etc/pacman.conf を編集して [multilib] リポジトリをアンコメントしてください:

[multilib]
Include = /etc/pacman.d/mirrorlist

公式リポジトリから gcc-multilibインストールしてください。

$HOME/.makepkg.conf に以下の行を追加するだけで x86_64 で i686 用のパッケージをコンパイルできます:

CARCH="i686"
CHOST="i686-pc-linux-gnu"
CFLAGS="-march=i686 -O2 -pipe -m32"
CXXFLAGS="${CFLAGS}"

次のコマンドで makepkg を呼び出して下さい:

$ linux32 makepkg -src

i686 パッケージをコンパイルし終わった後は $HOME/.makepkg.conf を忘れずに削除または修正してください。

Tips/Tricks

HDD/SSD の使用量を制限する

$HOME/.distcc を移動する

By default, distcc creates $HOME/.distcc which stores transient relevant info as it serves up work for nodes to compile. Create a directory named .distcc in RAM such as /tmp and soft link to it in $HOME. This will avoid needless HDD read/writes and is particularly important for SSDs.

$ mv $HOME/.distcc /tmp
$ ln -s /tmp/.distcc $HOME/.distcc

Use systemd to re-create this directory on a reboot (the soft link will remain until it is manually removed like any other file):

Create the following tmpfile where "X" is the letter for the SSD device.

 /etc/tmpfiles.d/tmpfs-create.conf 
d /tmp/.distcc 0755 <username> users -

ログレベルを設定する

By default, distcc will log to /var/log/messages.log as it goes along. One trick (actually recommended in the distccd manpage) is to log to an alternative file directly. Again, one can locate this in RAM via /tmp. Another trick is to lower to log level of minimum severity of error that will be included in the log file. Useful if only wanting to see error messages rather than an entry for each connection. LEVEL can be any of the standard syslog levels, and in particular critical, error, warning, notice, info, or debug.

Both of these lines are to be appended to DISTCC_ARGS in /etc/conf.d/distccd

DISTCC_ARGS="--user nobody --allow 192.168.0.0/24 --log-level error --log-file /tmp/distccd.log"

CMake や他のツールでビルドが失敗する

CMake sometimes pass "response file" to gcc, but the distcc cannot deal with it. There is a patch file, but it has not been applied to upstream code. If you encounter this problem, you can path this file or use the distcc-rspAUR package in the AUR.