resurrect dying workers

This commit is contained in:
Vincent Riquer 2013-03-26 17:15:44 +01:00
parent 5f98543054
commit eb977b91bd

67
atom
View File

@ -1230,41 +1230,8 @@ encodeFile::vorbis() {
progressSpin progressSpin
} }
checkFinished() {
#retrieve info from finished transcodeFile()
#update counters / metadata
:
}
checkLoad() {
#if load > threshold
# decrease concurrency
#elif load < threshold
# increase concurrency
#fi
:
}
readUserInput() {
#read + / - / q(uit) / p(ause)
#initiate shutdown / change load threshold / SIGSTOP all children / SIGCONT all children
:
}
transcodeLauncher() {
checkLoad
checkFinished
#until running processes < max processes
#do
checkLoad
checkFinished
readUserInput
#done
transcodeFile &
#update counter / metadata
}
worker() { worker() {
trap "kill -USR1 $masterpid" EXIT
set +e set +e
while : while :
do do
@ -1392,12 +1359,13 @@ master() {
'work') 'work')
if [ -n "$quit" ] if [ -n "$quit" ]
then then
dyingworker=${workers[workerid]}
unset workers[workerid]
eval echo AtOM:Die '>&'$((100+workerid)) eval echo AtOM:Die '>&'$((100+workerid))
wait ${workers[workerid]} wait $dyingworker
eval $((100+workerid))'>&-' eval $((100+workerid))'>&-'
eval $((200+workerid))'<&-' eval $((200+workerid))'<&-'
rm "$tempdir"/worker${workerid}{in,out} rm "$tempdir"/worker${workerid}{in,out}
unset workers[workerid]
elif (( active < concurrency )) elif (( active < concurrency ))
then then
echo ' echo '
@ -1457,12 +1425,13 @@ master() {
read -u4 ready read -u4 ready
if (( remaining == 0 )) if (( remaining == 0 ))
then then
dyingworker=${workers[workerid]}
unset workers[workerid]
eval echo AtOM:Die '>&'$((100+workerid)) eval echo AtOM:Die '>&'$((100+workerid))
wait ${workers[workerid]} wait $dyingworker
eval $((100+workerid))'>&-' eval $((100+workerid))'>&-'
eval $((200+workerid))'<&-' eval $((200+workerid))'<&-'
rm "$tempdir"/worker${workerid}{in,out} rm "$tempdir"/worker${workerid}{in,out}
unset workers[workerid]
continue continue
elif (( ready == 0 )) elif (( ready == 0 ))
then then
@ -1475,12 +1444,13 @@ master() {
fi fi
eval echo '"$line" >&'$((100+workerid)) eval echo '"$line" >&'$((100+workerid))
else else
dyingworker=${workers[workerid]}
unset workers[workerid]
eval echo AtOM:Die '>&'$((100+workerid)) eval echo AtOM:Die '>&'$((100+workerid))
wait ${workers[workerid]} wait $dyingworker
eval $((100+workerid))'>&-' eval $((100+workerid))'>&-'
eval $((200+workerid))'<&-' eval $((200+workerid))'<&-'
rm "$tempdir"/worker${workerid}{in,out} rm "$tempdir"/worker${workerid}{in,out}
unset workers[workerid]
fi fi
;; ;;
?(f)'inished') ?(f)'inished')
@ -1538,6 +1508,21 @@ master() {
fi fi
} }
checkworkers() {
for key in ${!workers[@]}
do
if ! kill -0 ${workers[key]}
then
worker $key \
<"$tempdir"/worker${key}in \
>"$tempdir"/worker${key}out &
workers[key]=$!
eval exec $((100+key))'>"$tempdir"/worker${key}in'
eval exec $((200+key))'<"$tempdir"/worker${key}out'
fi
done
}
#UI #UI
if [ ! -f ~/.atom/atom.cfg ] if [ ! -f ~/.atom/atom.cfg ]
@ -1980,6 +1965,8 @@ done
echo 'COMMIT;' >&3 echo 'COMMIT;' >&3
echo -e "\rCreated ${count:-0} tasks for $filecount files (${copies:-0} immediate copies)" echo -e "\rCreated ${count:-0} tasks for $filecount files (${copies:-0} immediate copies)"
masterpid=$$
trap checkworkers USR1
rm -f "$tempdir"/worker* rm -f "$tempdir"/worker*
concurrency=$(( maxload / 2 )) concurrency=$(( maxload / 2 ))
(( concurrency )) || concurrency=1 (( concurrency )) || concurrency=1