-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjft-run
executable file
·139 lines (120 loc) · 4.26 KB
/
jft-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/sh
### Usage: jft-run -h
### Usage: jft-run -f NODEFILE # file listing the list of available nodes (entries are hostname@type, see traces for available types)
### Usage: jft-run -n N # number of nodes from the nodefile to use
### Usage: jft-run -r RATE # limit this client bandwidth to RATE (units are: kbps, mbps, kbit, mbit or bps)
### Usage: jft-run -s FSIZE # file size in bytes
### Usage: jft-run -b BLKSIZE # block size in bytes
usage()
{
perl -ne '/^### Usage:/ && do { s/^### ?//; print }' < $0
exit 1
}
help()
{
perl -ne '/^###/ && do { s/^### ?//; print }' < $0
exit 0
}
# Parse command line arguments
HOSTS= N= RATE= FSIZE= BLKSIZE=
eval set -- $(getopt -n $0 -o hs:n:f:r:s:b: -- ${1+"$@"})
[ $? = 0 ] || usage
for arg; do
case $arg in
-n) N="$2"; shift; shift ;;
-f) [ -f $2 ] && HOSTS=$(cat $2); shift; shift ;;
-r) RATE="$2"; shift; shift ;;
-s) FSIZE="$2"; shift; shift ;;
-b) BLKSIZE="$2"; shift; shift ;;
-h) help ;;
--) shift; break ;;
-*) usage ;;
esac
done
[ $# = 0 ] || usage
[ X"$HOSTS" = X ] && usage
[ X"$N" = X ] && usage
[ $(echo $HOSTS | wc -w) -lt $N ] &&
{ echo "Do not have enough nodes in the nodefile."; exit 1; }
[ X"$RATE" = X ] && usage
[ X"$FSIZE" = X ] && usage
[ X"$BLKSIZE" = X ] && usage
grid-proxy-info -exists ||
{ echo "Proxy does not exist or expired"; exit 1; }
set -e
# Prepare to run
HOSTS=$(echo $HOSTS | cut -d" " -f-$N)
for host in $HOSTS; do
h=${host%%@*}; htype=$(echo ${host##*@} | cut -d"/" -f1)
hmaxbw=${host##*/}
echo "Preparing $h..."
ssh $h sudo chown -R $USER:zh /data/{state,cfg} 2> /dev/null | true
rsync -zavmH --delete -f '-s .svn' -f '-s .git' /data/cfg/ $h:/data/cfg/
(echo "exec 2>&1; set -ex; hostname -f; cd $PWD"
echo "sudo /etc/init.d/globus-gridftp-server restart"
echo "mkdir -p /data/state"
echo "sudo nohup /data/cfg/jft-shaper -i 120 -t $htype -b $hmaxbw &> /data/state/shaper.out &"
# start the node disconection simulator
) | ssh $h bashs -l
done
for host in $HOSTS; do
h=${host%%@*}; htype=$(echo ${host##*@} | cut -d"/" -f1)
FILE=/data/state/arquivao
# Recreates FILE on each host if does not exist or size is not enough
# Then splits it in BLKSIZE different files due to gridftp limitations to
# to specify the byte range and to write in parallel to the same file
(echo "[ -f $FILE ] && [ \$(stat -c%s $FILE) -ge $FSIZE ] || \\"
echo " dd if=/dev/urandom of=$FILE bs=4k count=$(($FSIZE/4096+1))"
echo "split -a 5 -d -b $BLKSIZE $FILE ${FILE}."
) | ssh $h bashs -l &
done
wait
# Used to transfer each block separately
TMPFILES='/data/state/transfered*'
# Do allways clean tmp files upon exit
# also reset the client bandwidth rate to default
trap "sudo /sbin/tc qdisc del dev seth0 root tbf; \
set -x;
rm $TMPFILES; \
for host in \$HOSTS; do \
ssh \${host%%@*} bashs -c 'echo test; /usr/bin/sudo /usr/bin/killall jft-shaper'; \
done;" EXIT SIGTERM SIGINT
# Set the client bandwidth
sudo /sbin/tc qdisc add dev seth0 root tbf rate $RATE latency 50ms burst 1540
#
# Run
#
echo "Starting the transfer..."
exec 3>&1 4>&2 # save stdout and stderr
# Make sure it is clean
rm -rf /data/state/transfered*
rm -rf /data/state/out* # stores each node's screen output
rm -rf /data/state/arquivao # final destine file
ti=$(date +%s)
c=$(( ($FSIZE+$BLKSIZE-1)/$BLKSIZE )) p=100000
for host in $HOSTS; do
h=${host%%@*}; htype=$(echo ${host##*@} | cut -d"/" -f1)
exec &> /data/state/out.$h
for i in $(seq $p $(($p+($c+$N-1)/$N - 1))); do
{ tii=$(date +%s);
#echo $i # $(( ($FSIZE - ${i#1}*$BLKSIZE - 1) % $BLKSIZE + 1))
globus-url-copy \
gsiftp://$h/data/state/arquivao.${i#1} \
file:///data/state/transfered.${i#1};
# debug output entries are: blocknr initial_time endtime
echo "${i#1} $tii $(date +%s)";
} &
done
p=$(($p+($c+$N-1)/$N))
done
exec 1>&3 2>&4 # restore stdout and stderr
wait # wait all processes to finish
# prints statistics about the transfer
dur=$((`date +%s` - $ti)) # total transfer duration time in seconds
echo "$N $RATE $BLKSIZE $FSIZE $dur" >> /data/state/stats
# reconstructs the file from the transfered blocks
cat /data/state/transfered.* >> /data/state/arquivao
# generate plots
/data/cfg/jft-plot /data/state/stats
echo "Done."
exit 0