Added start-delay for workers to spread the load.

This commit is contained in:
Louwrentius 2009-10-24 19:53:35 +00:00
parent 4d28218ce4
commit 722b3b4ea6

21
ppss.sh
View File

@ -76,7 +76,8 @@ ARRAY_POINTER_FILE="$PPSS_DIR/ppss-array-pointer-$PID" # Pointer for keeping tr
JOB_LOG_DIR="$PPSS_DIR/job_log" # Directory containing log files of processed items. JOB_LOG_DIR="$PPSS_DIR/job_log" # Directory containing log files of processed items.
LOGFILE="$PPSS_DIR/ppss-log-$$.txt" # General PPSS log file. Contains lots of info. LOGFILE="$PPSS_DIR/ppss-log-$$.txt" # General PPSS log file. Contains lots of info.
STOP=0 # STOP job. STOP=0 # STOP job.
MAX_DELAY=3 MAX_DELAY=0 # MAX DELAY between jobs.
MAX_LOCK_DELAY=3 #
PERCENT="0" PERCENT="0"
LISTENER_PID="" LISTENER_PID=""
IFS_BACKUP="$IFS" IFS_BACKUP="$IFS"
@ -114,10 +115,11 @@ showusage_short () {
echo echo
echo "usage: $0 [ -d <sourcedir> | -f <sourcefile> ] [ -c '<command> \"$ITEM\"' ]" echo "usage: $0 [ -d <sourcedir> | -f <sourcefile> ] [ -c '<command> \"$ITEM\"' ]"
echo " [ -C <configfile> ] [ -j ] [ -l <logfile> ] [ -p <# jobs> ]" echo " [ -C <configfile> ] [ -j ] [ -l <logfile> ] [ -p <# jobs> ]"
echo " [ -D <delay> ]"
echo echo
echo "Examples:" echo "Examples:"
echo " $0 -d /dir/with/some/files -c 'gzip '" echo " $0 -d /dir/with/some/files -c 'gzip '"
echo " $0 -d /dir/with/some/files -c 'gzip \"$ITEM\"'" echo " $0 -d /dir/with/some/files -c 'gzip \"$ITEM\"' -D 5"
echo " $0 -d /dir/with/some/files -c 'cp \"$ITEM\" /tmp' -p 2" echo " $0 -d /dir/with/some/files -c 'cp \"$ITEM\" /tmp' -p 2"
} }
@ -278,7 +280,7 @@ kill_process () {
kill -9 "$SSH_MASTER_PID" >> /dev/null 2>&1 kill -9 "$SSH_MASTER_PID" >> /dev/null 2>&1
fi fi
sleep 1 sleep 1
log INFO "Finished." log INFO "Finished. Consult ./$JOB_LOG_DIR for job output."
} }
exec_cmd () { exec_cmd () {
@ -433,6 +435,11 @@ do
add_var_to_config SRC_DIR "$SRC_DIR" add_var_to_config SRC_DIR "$SRC_DIR"
shift 2 shift 2
;; ;;
--delay|-D)
MAX_DELAY="$2"
add_var_to_config MAX_DELAY "$MAX_DELAY"
shift 2
;;
--command|-c ) --command|-c )
COMMAND=$2 COMMAND=$2
if [ "$MODE" == "config" ] if [ "$MODE" == "config" ]
@ -1043,7 +1050,7 @@ get_global_lock () {
ERROR="$?" ERROR="$?"
if [ ! "$ERROR" == "0" ] if [ ! "$ERROR" == "0" ]
then then
random_delay $MAX_DELAY random_delay $MAX_LOCK_DELAY
continue continue
else else
break break
@ -1264,7 +1271,6 @@ get_item () {
# This variable is used to walk thtough all array items. # This variable is used to walk thtough all array items.
ARRAY_POINTER=`cat $ARRAY_POINTER_FILE` ARRAY_POINTER=`cat $ARRAY_POINTER_FILE`
# Check if all items have been processed. # Check if all items have been processed.
if [ "$ARRAY_POINTER" -ge "$SIZE_OF_ARRAY" ] if [ "$ARRAY_POINTER" -ge "$SIZE_OF_ARRAY" ]
then then
@ -1522,6 +1528,11 @@ start_all_workers () {
do do
start_single_worker start_single_worker
((i++)) ((i++))
if [ ! "$MAX_DELAY" == "0" ]
then
random_delay "$MAX_DELAY"
fi
done done
} }