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 Apr 20, 2024
1 parent 3f33775 commit 062ead8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/share/poudriere/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4902,6 +4902,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 @@ -5032,6 +5049,7 @@ build_port() {
job_build_status "${phase}/timeout" \
"${originspec}" "${pkgname}"
fi
rm -f "${build_semaphore_path}"
return 1
fi
;;
Expand Down Expand Up @@ -5062,6 +5080,13 @@ build_port() {
;;
esac

case "${phase}" in
"build")
job_msg "Build semaphore ${build_semaphore_path} out"
rm -f "${build_semaphore_path}"
;;
esac

case "${PORTTESTING}${phase}" in
"1""stage")
local die=0
Expand Down

0 comments on commit 062ead8

Please sign in to comment.