Skip to content

Instantly share code, notes, and snippets.

@jhgorse
Created March 30, 2017 18:06
Show Gist options
  • Save jhgorse/5afcb868747f0aa3a44142b701fabf55 to your computer and use it in GitHub Desktop.
Save jhgorse/5afcb868747f0aa3a44142b701fabf55 to your computer and use it in GitHub Desktop.
parallel stat test
#!/usr/bin/env bash
# parallel testing
#
# arg: basename of the test
# output: results/$basename_`date +"%m-%d-%H_%m_%S"`/
# assumes we are in same directory with afs_dir_test_setup.sh
pids=""
maxproc=$( bc <<< "`nproc`*2" )
# maxproc=4
# parse arg 1, test basename
if [[ -n "$1" ]]; then basename="$1"; fi
if [ -z $basename ]; then echo ""; basename="pfind_time"; fi
echo "setting basename to $basename"
#parse arg 2, test directory
if [[ -n "$2" ]]; then testdir="$2"; fi
if [ -z $testdir ]; then echo ""; testdir="/afs/.robotest"; fi
echo "setting testdir to $testdir"
$PWD/afs_dir_test_setup.sh $testdir
if [[ $? -ne 0 ]]; then echo dying on setup: $?; exit 1; fi
results_dir=$PWD/results/${basename}_`date +"%m-%d-%H_%M_%S"`
mkdir $results_dir
longprocess() {
# Sleep up to 6 seconds
sleep $((3 + RANDOM % 3))
# Randomly exit with 0 or 1
exit $((RANDOM % 2))
}
for i in $(seq 1 ${maxproc}); do
# echo "i ${i}"
for j in $(seq 1 ${i}); do
# echo " { time find $testdir/dir1 | xargs stat > /dev/null 2>&1 ; } 2> $results_dir/${basename}_${i}_${j}.out &"
$({ time find $testdir/dir1 | xargs stat > /dev/null 2>&1 ; } 2> $results_dir/${basename}_${i}_${j}.out) &
# ( longprocess ) &
pids="${pids} $!"
done
wait ${pids}
pids=""
done
# average the output
# thanks to http://regexr.com/
#
# (1) pull out the row, (2) grab the seconds, (3) average it
# grep "real" pfind_time_1_*.out | sed -r 's/.*0m(.*)s/\1/' | awk '{ sum += $1 } END { if (NR > 0) print sum / NR }'
touch $results_dir/${basename}_data.txt
echo "" > $results_dir/${basename}_data.txt
for i in $(seq 1 ${maxproc}); do
echo "$(grep "real" $results_dir/${basename}_${i}_* | sed -r 's/.*0m(.*)s/\1/' | awk '{ sum += $1 } END { if (NR > 0) print sum / NR }')" >> $results_dir/${basename}_data.txt
done
cat $results_dir/${basename}_data.txt
@jhgorse
Copy link
Author

jhgorse commented Mar 30, 2017

Batch test with:

#!/usr/bin/env bash

for i in {1..10}; do
  echo $i
  ./parallel_find_test.sh master_afs /afs/.robotest
done

for i in {11..20}; do
  echo $i
  ./parallel_find_test.sh master_ext4 /tmp
done

echo "All done!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment