Only build in parallel if the build machine is >8G

This commit is contained in:
Zach Loafman 2015-04-02 08:46:28 -07:00
parent e159c02a2a
commit c0ed73a10d

View File

@ -72,6 +72,11 @@ readonly KUBE_CLIENT_PLATFORMS=(
windows/amd64 windows/amd64
) )
# Gigabytes desired for parallel platform builds. 8 is fairly
# arbitrary, but is a reasonable splitting point for 2015
# laptops-versus-not.
readonly KUBE_PARALLEL_BUILD_MEMORY=8
readonly KUBE_ALL_TARGETS=( readonly KUBE_ALL_TARGETS=(
"${KUBE_SERVER_TARGETS[@]}" "${KUBE_SERVER_TARGETS[@]}"
"${KUBE_CLIENT_TARGETS[@]}" "${KUBE_CLIENT_TARGETS[@]}"
@ -321,6 +326,29 @@ kube::golang::build_binaries_for_platform() {
} }
# Return approximate physical memory in gigabytes.
kube::golang::get_physmem() {
local mem
# Linux, in kb
if mem=$(grep MemTotal /proc/meminfo | awk '{ print $2 }'); then
echo $(( ${mem} / 1048576 ))
return
fi
# OS X, in bytes. Note that get_physmem, as used, should only ever
# run in a Linux container (because it's only used in the multiple
# platform case, which is a Dockerized build), but this is provided
# for completeness.
if mem=$(sysctl -n hw.memsize 2>/dev/null); then
echo $(( ${mem} / 1073741824 ))
return
fi
# If we can't infer it, just give up and assume a low memory system
echo 1
}
# Build binaries targets specified # Build binaries targets specified
# #
# Input: # Input:
@ -371,13 +399,28 @@ kube::golang::build_binaries() {
local binaries local binaries
binaries=($(kube::golang::binaries_from_targets "${targets[@]}")) binaries=($(kube::golang::binaries_from_targets "${targets[@]}"))
local parallel=false
if [[ ${#platforms[@]} -gt 1 ]]; then
local gigs
gigs=$(kube::golang::get_physmem)
if [[ ${gigs} -gt ${KUBE_PARALLEL_BUILD_MEMORY} ]]; then
kube::log::status "Multiple platforms requested and available ${gigs}G > threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in parallel"
parallel=true
else
kube::log::status "Multiple platforms requested, but available ${gigs}G < threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in serial"
parallel=false
fi
fi
if [[ "${parallel}" == "true" ]]; then
kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}" kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"
local platform local platform
for platform in "${platforms[@]}"; do ( for platform in "${platforms[@]}"; do (
kube::golang::set_platform_envs "${platform}" kube::golang::set_platform_envs "${platform}"
kube::log::status "${platform}: Parallel go build started" kube::log::status "${platform}: go build started"
kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-} kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}
kube::log::status "${platform}: Parallel go build finished" kube::log::status "${platform}: go build finished"
) &> "/tmp//${platform//\//_}.build" & ) &> "/tmp//${platform//\//_}.build" &
done done
@ -391,5 +434,12 @@ kube::golang::build_binaries() {
done done
exit ${fails} exit ${fails}
else
for platform in "${platforms[@]}"; do
kube::log::status "Building go targets for ${platform}:" "${targets[@]}"
kube::golang::set_platform_envs "${platform}"
kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}
done
fi
) )
} }