Skip to content

Instantly share code, notes, and snippets.

@krishnasrinivas
Created March 19, 2021 23:07
Show Gist options
  • Save krishnasrinivas/8cfc04c3222c7339586d3b0255073e09 to your computer and use it in GitHub Desktop.
Save krishnasrinivas/8cfc04c3222c7339586d3b0255073e09 to your computer and use it in GitHub Desktop.
#!/bin/bash
trap 'killall -9 parallel-dd' INT
# number of bytes per file
SIZE=12K
# number of threads
THREADS=100
# number of files per thread
FILES_PER_THREAD=300000
TMPDIR=$1
usage="USAGE: parallel-dd TMPDIR\n"
[ -z $TMPDIR ] && printf "$usage" && exit
mkdir -p $TMPDIR
for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
for k in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
for l in 0 1 2 3 4 5 6 7 8 9 a b c d e f
do
mkdir -p $TMPDIR/$i$j/$k$l
done
done
done
done
serial_dd() {
local thread=$1
mkdir -p ${TMPDIR}/$thread
# create 300000 files per thread (hence total of 30 million files)
for count in $(seq 1 ${FILES_PER_THREAD})
do
local uuidfile=`uuidgen`
local part1=`expr substr $uuidfile 1 2`
local part2=`expr substr $uuidfile 3 2`
echo $((time (dd if=/dev/zero of=${TMPDIR}/$part1/$part2/$uuidfile bs=${SIZE} count=1 oflag=direct ) 2>&1 ) | grep real | sed -e 's/real//' | tr -d '\t')
done
}
parallel_dd() {
for i in $(seq 1 ${THREADS})
do
serial_dd $i &
pids[${i}]=$!
done
for pid in ${pids[*]}; do
wait $pid
done
echo -n "Total time: "
}
time parallel_dd 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment