概述

LSF lsmake 是一个与 LSF 紧密集成的并行 GNU make 工具。

lsmake 特点

特点 说明
兼容性 完全兼容 GNU make 命令行工具
并行能力 可将任务分发到多个 LSF 主机的处理器上并行运行
免费使用 LSF 用户无需额外许可证

与 gmake 的区别

  • gmake -j:在单主机的多处理器上并行构建
  • lsmake:可将任务分发到多个 LSF 主机的处理器上并行运行

环境准备

Android 构建环境

参考 Android 官方文档:

重要:要在多主机上并行构建 Android 源码,必须将源码下载到共享目录

LSF 环境

确保所有计算主机上的 LSF RES 守护进程正在运行。

验证环境

1
2
3
4
5
6
7
8
9
10
11
12
13
$ lsload
HOST_NAME  status  r15s   r1m  r15m   ut    pg    ls   it   tmp   swp   mem
ubun01     ok      0.0    0.0   0.1   0%   0.0    1  160   14G  1016M  1.2G
ubun02     ok      0.0    0.0   0.1   0%   0.0    1  160   14G  1016M  1.2G
ubun03     ok      0.0    0.0   0.1   0%   0.0    1  160   14G  1016M  1.2G
ubun04     ok      0.0    0.0   0.1   0%   0.0    1  160   14G  1016M  1.2G

$ bhosts
HOST_NAME  STATUS  JL/U  MAX  NJOBS  RUN  SSUSP  USUSP  RSV
ubun01     ok      -     4    0      0    0      0      0
ubun02     ok      -     4    0      0    0      0      0
ubun03     ok      -     4    0      0    0      0      0
ubun04     ok      -     4    0      0    0      0      0

单主机构建

提交 lsmake 作为 LSF 作业,使用单主机的 4 个槽位:

1
2
$ bsub -n 4 -R "span[hosts=1]" -o %J.out -cwd /share/android lsmake --no-block-shell-mode
Job <361> is submitted to default queue <normal>.

参数说明

参数 说明
-n 4 请求 4 个槽位
-R "span[hosts=1]" 所有槽位必须在同一主机
-o %J.out 输出重定向到 JOB_ID.out
-cwd /share/android 指定工作目录
--no-block-shell-mode lsmake 选项,优化 SHELL 命令性能

检查作业状态

1
2
3
4
5
6
7
$ bjobs -l 361
Job <361>, User <lsfuser>, Project <default>, Status <DONE>, Queue <normal>,
Command <lsmake --no-block-shell-mode>,
Mon Dec  8 12:44:40: Submitted from host <ubun01>, CWD </home/lsfuser>;
Mon Dec  8 12:44:41: Started on <ubun01>, Execution Home </home/lsfuser>,
                     Specified CWD </share/android>;
Mon Dec  8 12:44:43: Done successfully. The CPU time used is 18,012 seconds.

检查构建结果

1
2
3
4
5
6
$ tail 361.out
Done!
Install: out/target/product/generic/system/app/Gallery2.odex
Install: out/target/product/generic/system/app/Gallery2.apk
...
Install system fs image: out/target/product/generic/system.img

多主机构建

提交 lsmake 作为 LSF 作业,使用 4 个主机共 16 个槽位:

1
2
$ bsub -n 16 -R "span[ptile=4]" -o %J.out -cwd /share/android lsmake --no-block-shell-mode
Job <362> is submitted to default queue <normal>.

参数说明

参数 说明
-n 16 请求 16 个槽位
-R "span[ptile=4]" 每主机 4 个槽位,共 4 个主机

性能对比

构建方式 主机数与多核 构建时间
gmake -j4 1:25:21
lsmake -j4 (1 host) 1:28:02
lsmake -j8 (2 hosts) 49:31
lsmake -j16 (4 hosts) 28:19

结论:使用 4 个主机,lsmake 将构建时间从 1 小时 25 分钟缩短到 28 分钟,加速约 3 倍

lsmake 关键选项

选项 说明
-a seconds 延迟时间
-E 环境变量
-u 创建data file 并且每秒钟更新它
-x 重试次数
-y job 完成后显示summary信息
--no-block-shell-mode 优化 Makefile 中 SHELL 命令的性能
-j N 指定并行作业数

参考资料

  1. IBM Documentation - Using lsmake to accelerate Android builds
  2. IBM Documentation - lsmake command reference
  3. Android - Initializing a Build Environment