Skip to content

Commit

Permalink
Build Semaphore: Working prototype.
Browse files Browse the repository at this point in the history
Proof of concept. DO NOT MERGE!

Create a semaphore, to restrict the number of builders that may enter
the "build" phase of their ports. This number is controlled by the
"BUILD_SEMAPHORE" setting. With a setting of e.g. "BUILD_SEMAPHORE=3",
no more than 3 builders are allowed to enter the "build" phase at a
time. Other phases are unaffected, they are only limited by the total
number of builders ("PARALLEL_JOBS").
  • Loading branch information
0EVSG committed Jan 21, 2022
1 parent 42d7476 commit 69bafb6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/share/poudriere/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4272,6 +4272,23 @@ build_port() {
markfs prebuild ${mnt}
fi
;;
build)
build_semaphore_dir="/tmp/build_semaphore/${BUILDNAME}"
mkdir -p "${build_semaphore_dir}"
build_semaphore_wait=${max_execution_time}
build_semaphore_path="${build_semaphore_dir}/${pkgname}"
build_semaphore_size=${BUILD_SEMAPHORE=${PARALLEL_JOBS}}
if [ ! -f "${build_semaphore_path}" ]; then
lockf -k "${build_semaphore_dir}/.lock" \
timeout ${build_semaphore_wait} sh -c "
trap 'touch \"${build_semaphore_path}\"' 0
trap 'rm -f \"${build_semaphore_dir}\"/*; exit 1' TERM
while [ \`ls -I \"${build_semaphore_dir}\" | wc -l\` -ge ${build_semaphore_size} ]; do
sleep 1
done"
job_msg "Build semaphore ${build_semaphore_path} in"
fi
;;
run-depends)
JUSER=root
if [ "${PORTTESTING}" -eq 1 ]; then
Expand Down Expand Up @@ -4392,6 +4409,7 @@ build_port() {
"${originspec}" "${pkgname}"
job_msg_verbose "Status ${COLOR_PORT}${port}${flavor:+@${flavor}} | ${pkgname}${COLOR_RESET}: ${COLOR_PHASE}timeout"
fi
rm -f "${build_semaphore_path}"
return 1
fi
fi
Expand All @@ -4409,6 +4427,11 @@ build_port() {
return 1
fi

if [ "${phase}" = "build" ]; then
job_msg "Build semaphore ${build_semaphore_path} out"
rm -f "${build_semaphore_path}"
fi

if [ "${phase}" = "stage" -a "${PORTTESTING}" -eq 1 ]; then
local die=0

Expand Down

0 comments on commit 69bafb6

Please sign in to comment.