Skip to content

Commit 1692f5b

Browse files
czentgrfacebook-github-bot
authored andcommitted
misc(build): Add variable to configure dependency build parallelism (facebookincubator#12156)
Summary: This change adds the BUILD_THREADS environment variable. This controls the parallelism used when building dependencies. By default, the number of cores in the host machine is used but can result in OOM kills. For example, on machines with 8 cores and 16GB ram (plus 16GB swap) OOM kills can be observed. This change allows a user to configure a flexible build automation. Pull Request resolved: facebookincubator#12156 Reviewed By: kgpai Differential Revision: D68746594 Pulled By: xiaoxmeng fbshipit-source-id: 589ae16013d99ad541251f3c8ba32a1337c7a0f7
1 parent 68fcaa1 commit 1692f5b

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ subsequent Velox builds can use the installed packages.
131131
*You can reuse `DEPENDENCY_INSTALL` and `INSTALL_PREFIX` for Velox clients such as Prestissimo
132132
by specifying a common shared directory.`*
133133

134+
The build parallelism for dependencies can be controlled by the `BUILD_THREADS` environment
135+
variable and overrides the default number of parallel processes used for compiling and linking.
136+
The default value is the number of cores on your machine.
137+
This is useful if your machine has lots of cores but no matching memory to process all
138+
compile and link processes in parallel resulting in OOM kills by the kernel.
139+
134140
### Setting up on macOS
135141

136142
On a macOS machine (either Intel or Apple silicon) you can setup and then build like so:

scripts/setup-centos9.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set -efx -o pipefail
3030
# so that some low level types are the same size. Also, disable warnings.
3131
SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")
3232
source $SCRIPTDIR/setup-helper-functions.sh
33-
NPROC=$(getconf _NPROCESSORS_ONLN)
33+
NPROC=${BUILD_THREADS:-$(getconf _NPROCESSORS_ONLN)}
3434
export CXXFLAGS=$(get_cxx_flags) # Used by boost.
3535
export CFLAGS=${CXXFLAGS//"-std=c++17"/} # Used by LZO.
3636
CMAKE_BUILD_TYPE="${BUILD_TYPE:-Release}"

scripts/setup-helper-functions.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
DEPENDENCY_DIR=${DEPENDENCY_DIR:-$(pwd)/deps-download}
2020
OS_CXXFLAGS=""
21+
NPROC=${BUILD_THREADS:-$(getconf _NPROCESSORS_ONLN)}
2122

2223
function run_and_time {
2324
time "$@" || (echo "Failed to run $* ." ; exit 1 )
@@ -214,7 +215,7 @@ function cmake_install {
214215
-DBUILD_TESTING=OFF \
215216
"$@"
216217
# Exit if the build fails.
217-
cmake --build "${BINARY_DIR}" || { echo 'build failed' ; exit 1; }
218+
cmake --build "${BINARY_DIR}" "-j ${NPROC}" || { echo 'build failed' ; exit 1; }
218219
${SUDO} cmake --install "${BINARY_DIR}"
219220
}
220221

scripts/setup-macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ PYTHON_VENV=${PYTHON_VENV:-"${SCRIPTDIR}/../.venv"}
3636
# by tagging the brew packages to be system packages.
3737
# This is used during package builds.
3838
export OS_CXXFLAGS=" -isystem $(brew --prefix)/include "
39-
NPROC=$(getconf _NPROCESSORS_ONLN)
39+
NPROC=${BUILD_THREADS:-$(getconf _NPROCESSORS_ONLN)}
4040

4141
BUILD_DUCKDB="${BUILD_DUCKDB:-true}"
4242
VELOX_BUILD_SHARED=${VELOX_BUILD_SHARED:-"OFF"} #Build folly shared for use in libvelox.so.

scripts/setup-ubuntu.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ source $SCRIPTDIR/setup-helper-functions.sh
3434
# are the same size.
3535
COMPILER_FLAGS=$(get_cxx_flags)
3636
export COMPILER_FLAGS
37-
NPROC=$(getconf _NPROCESSORS_ONLN)
37+
NPROC=${BUILD_THREADS:-$(getconf _NPROCESSORS_ONLN)}
3838
BUILD_DUCKDB="${BUILD_DUCKDB:-true}"
3939
export CMAKE_BUILD_TYPE=Release
4040
VELOX_BUILD_SHARED=${VELOX_BUILD_SHARED:-"OFF"} #Build folly shared for use in libvelox.so.

0 commit comments

Comments
 (0)