Optimisations for image compression when building in parallel

This commit is contained in:
Igor Pecovnik 2021-06-13 11:06:40 +02:00
parent 307effa8e9
commit e94cbfae47

View File

@ -773,8 +773,18 @@ create_image()
if [[ $COMPRESS_OUTPUTIMAGE == *xz* ]]; then
display_alert "Compressing" "${FINALDEST}/${version}.img.xz" "info"
# compressing consumes a lot of memory we don't have. Waiting for previous packing job to finish helps to run a lot more builds in parallel
[[ ${BUILD_ALL} == yes && $(free | grep Mem | awk '{print $4/$2 * 100.0}' | awk '{print int($1)}') -lt 5 ]] && while [[ $(ps -uax | grep "pixz" | wc -l) -gt 4 ]]; do echo -en "#"; sleep 20; done
pixz -8 -p 12 < $DESTIMG/${version}.img > ${FINALDEST}/${version}.img.xz
available_cpu=$(grep -c 'processor' /proc/cpuinfo)
[[ ${BUILD_ALL} == yes ]] && available_cpu=$(( $available_cpu * 30 / 100 )) # lets use 20% of resources in case of build-all
[[ ${available_cpu} -gt 8 ]] && available_cpu=8 # using more cpu cores for compressing is pointless
available_mem=$(LC_ALL=c free | grep Mem | awk '{print $4/$2 * 100.0}' | awk '{print int($1)}') # in percentage
# build optimisations when memory drops below 5%
if [[ ${BUILD_ALL} == yes && ${available_mem} -lt 15 ]]; then
while [[ $(ps -uax | grep "pixz" | wc -l) -gt 2 ]]
do echo -en "#"
sleep 20
done
fi
pixz -8 -p ${available_cpu} < $DESTIMG/${version}.img > ${FINALDEST}/${version}.img.xz
compression_type=".xz"
fi