Commit c0ed73a1 authored by Zach Loafman's avatar Zach Loafman

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

parent e159c02a
...@@ -72,6 +72,11 @@ readonly KUBE_CLIENT_PLATFORMS=( ...@@ -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() { ...@@ -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,25 +399,47 @@ kube::golang::build_binaries() { ...@@ -371,25 +399,47 @@ kube::golang::build_binaries() {
local binaries local binaries
binaries=($(kube::golang::binaries_from_targets "${targets[@]}")) binaries=($(kube::golang::binaries_from_targets "${targets[@]}"))
kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}" local parallel=false
local platform if [[ ${#platforms[@]} -gt 1 ]]; then
for platform in "${platforms[@]}"; do ( local gigs
kube::golang::set_platform_envs "${platform}" gigs=$(kube::golang::get_physmem)
kube::log::status "${platform}: Parallel go build started"
kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}
kube::log::status "${platform}: Parallel go build finished"
) &> "/tmp//${platform//\//_}.build" &
done
local fails=0 if [[ ${gigs} -gt ${KUBE_PARALLEL_BUILD_MEMORY} ]]; then
for job in $(jobs -p); do kube::log::status "Multiple platforms requested and available ${gigs}G > threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in parallel"
wait ${job} || let "fails+=1" parallel=true
done else
kube::log::status "Multiple platforms requested, but available ${gigs}G < threshold ${KUBE_PARALLEL_BUILD_MEMORY}G, building platforms in serial"
for platform in "${platforms[@]}"; do parallel=false
cat "/tmp//${platform//\//_}.build" fi
done fi
exit ${fails} if [[ "${parallel}" == "true" ]]; then
kube::log::status "Building go targets for ${platforms[@]} in parallel (output will appear in a burst when complete):" "${targets[@]}"
local platform
for platform in "${platforms[@]}"; do (
kube::golang::set_platform_envs "${platform}"
kube::log::status "${platform}: go build started"
kube::golang::build_binaries_for_platform ${platform} ${use_go_build:-}
kube::log::status "${platform}: go build finished"
) &> "/tmp//${platform//\//_}.build" &
done
local fails=0
for job in $(jobs -p); do
wait ${job} || let "fails+=1"
done
for platform in "${platforms[@]}"; do
cat "/tmp//${platform//\//_}.build"
done
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
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment