Skip to content

Commit 3300bed

Browse files
committed
misc(build): Add variable to configure dependency build parallelism
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.
1 parent 5e238f4 commit 3300bed

5 files changed

+11
-4
lines changed

README.md

+6
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

+1-1
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

+2-1
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

+1-1
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

+1-1
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)