forked from Lainports/freebsd-ports
machine with the lowest number of running jobs. This worked when the clients were all roughly equivalent, but schedules poorly when there are some that are much more powerful (e.g. 8-core machines vs UP machines) * We now compute the ratio of running jobs to maximum jobs and schedule on the machine with lowest occupation fraction. This populates the machines to equal fractions of their capacity.
66 lines
1.2 KiB
Bash
Executable file
66 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Choose the least-loaded machine in the queue dir
|
|
# Called with lock held
|
|
# We know that everything in this directory has space for another job
|
|
|
|
pb=$1
|
|
arch=$2
|
|
branch=$3
|
|
|
|
qdir=${pb}/${arch}/queue
|
|
|
|
cd $qdir
|
|
set *
|
|
if [ "$1" = "*" ]; then
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
|
|
min=999999
|
|
while [ $# -gt 0 ]; do
|
|
m=$1
|
|
|
|
# Pull in maxjobs
|
|
. ${pb}/${arch}/portbuild.conf
|
|
test -f ${pb}/${arch}/portbuild.${m} && . ${pb}/${arch}/portbuild.${m}
|
|
|
|
curjobs=$(cat $m)
|
|
weight=$((${curjobs}*1000/${maxjobs}))
|
|
|
|
if [ $weight -lt $min ]; then
|
|
mach=$m
|
|
min=$weight
|
|
elif [ $weight -eq $min ]; then
|
|
mach="${mach} ${m}"
|
|
fi
|
|
shift
|
|
done
|
|
|
|
if [ "$min" = 999999 -o -z "${mach}" ]; then
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
# Choose highest-priority machine that is free
|
|
mach=$(echo ${mach} | tr -s ' ' '\n' | grep -F -f - ${pb}/${arch}/mlist | head -1)
|
|
if [ -z "${mach}" ]; then
|
|
rm -f "${mach}"
|
|
exit 1
|
|
fi
|
|
|
|
. ${pb}/${arch}/portbuild.conf
|
|
test -f ${pb}/${arch}/portbuild.${mach} && . ${pb}/${arch}/portbuild.${mach}
|
|
|
|
curjobs=$(cat $mach)
|
|
# Now that we've found a machine, register our claim in the queue
|
|
if [ "$((${curjobs}+1))" -ge "${maxjobs}" ]; then
|
|
rm ${mach}
|
|
else
|
|
echo $(($curjobs+1)) > ${mach}
|
|
fi
|
|
|
|
# Report to caller
|
|
echo ${mach}
|
|
exit 0
|