Icecream分布式编译加速Yocto BitBake

icecream是SUSE团队开发的分布式编译器。与distcc类似,都能用来组建build farm,但icecream还加入了scheduler的概念,使得所有编译机得到统一的协调管理。

Icecream 安装

安装icecc/icecream并启动后端服务:

1
2
3
$ sudo zypper in icecream icecream-monitor patchelf
$ sudo systemctl enable --now iceccd
$ sudo systemctl enable --now icecc-scheduler  # on scheduler

Icecream使用TCP 10245、8765、8766和UDP 8765端口。openSUSE可在yast2-firewall中找到预设的规则,放行即可。

Icecream的scheduler对CPU性能要求并不高,但对处理延迟比较敏感,因此建议跑icecc的编译机不要兼职scheduler。

For Ubuntu:

1
2
# apt install icecc icecream-sundae
#  # iceccd.service is automatically enabled on Ubuntu

安装好后可以在任意机器上跑一下icemonicecream-sundae,检查所有机器是否都在线。

BitBake配置

Yocto已经自带了Icecream支持。在conf/local.conf中添加:

1
2
INHERIT += " icecc"
ICECC_PARALLEL_MAKE = "-j 24"

部分软件用Icecream编译会因为各种各样奇怪的原因失败,可以通过ICECC_SYSTEM_PACKAGE_BLICECC_USER_PACKAGE_BL(~honister)或ICECC_RECIPE_DISABLE(kirkstone~)变量禁用这些包的并行编译:

1
2
3
4
# container-dummy-provides: ${HOST_PREFIX} is empty, which triggers the "NULL prefix" error
# ICECC_SYSTEM_PACKAGE_BL += " container-dummy-provides"  # Old syntax
# 2023-01-03 update: rust-related packages
ICECC_RECIPE_DISABLE += " container-dummy-provides cargo-native python3-cryptography-native"

执行编译即可观察到编译阶段所有编译机都会有较高CPU占用,可通过icemonicecream-sundae监视编译机的任务分配。系统响应还是会比每台机器独自编译占满CPU和内存时更流畅(uptime{,h}top等工具也可验证)。

1
bitbake: 芜湖起飞

Reference

  1. Sweeten Your Yocto Build Times with Icecream

  2. https://lore.kernel.org/all/20211103015201.572934-1-douglas.royds@taitradio.com/