-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathruncluster
executable file
·294 lines (242 loc) · 7.63 KB
/
runcluster
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#!/bin/bash
router=c11node28
target=c11node10
#target=10.5.147.210
ganglia=10.244.36.20
#postcopy=on
postcopy=off
#masterpost=on
masterpost=off
#migspeed=30
migspeed=125
rtt=$3
#rtt=180ms
#rtt=0.4ms
#ram=2048
ram=1800
vcpu=1
# log/idle/cluster/precopy/speed125/vcpu2/180ms/
logbasedir=/root/migration/log/idle/cluster
logdir=$logbasedir/precopy/speed$migspeed/vcpu$vcpu/$rtt
nvms=$1
run=$2
#prefix=2vms-r2
prefix=$logdir/${nvms}vms-r${run}
ports=( 4446 4447 4448 4449 4450 4451 )
#ports=( 4447 4448 4449 )
nports=${#ports[@]}
# boot up vm
preptime=90
# sleep interval
sleeptime=5
mkdir -p $logdir
remain=$nports
# for cpu utilization
PREV_TOTAL=0
PREV_IDLE=0
function startcluster() {
# generate a random mac address for the qemu nic
mac=`printf 'DE:AD:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))`
# filename ram vcpu telnetport vncport listenport postcopy
# master 10.244.36.132 (old 10.244.39.141)
mac=DE:AD:BE:EF:0C:0F
name=master
#./runvm-daemon ${name}.qcow2 $ram $vcpu 4446 1 $mac $name
# slave1 10.244.37.1
mac=DE:AD:BE:EF:FA:3A
#./runvm-daemon slave1.qcow2 $ram $vcpu 4447 2 $mac
# slave2 10.244.38.71
mac=DE:AD:BE:EF:FF:57
#./runvm-daemon slave2.qcow2 $ram $vcpu 4448 3 $mac
# slave3 10.244.38.70
mac=DE:AD:BE:EF:A6:75
#./runvm-daemon slave3.qcow2 $ram $vcpu 4449 4 $mac
# slave4 10.244.37.127
mac=DE:AD:BE:EF:5D:A2
#./runvm-daemon slave4.qcow2 $ram $vcpu ${ports[4]} 5 $mac
# slave5 10.244.36.115
mac=DE:AD:BE:EF:70:62
#./runvm-daemon slave5.qcow2 $ram $vcpu ${ports[5]} 6 $mac
tport=4446 # telnet port
mport=5446 # migration tcp port
vport=1 # vnc port
# slave6 10.244.39.141
slaveid=6
tport=$(( tport + 6 ))
vport=$(( vport + 6 ))
mac=DE:AD:BE:EF:48:B4
#./runvm-daemon slave${slaveid}.qcow2 $ram $vcpu $tport $vport $mac
# slave7 10.244.39.141
slaveid=$(( slaveid + 1 ))
tport=$(( tport + 1 ))
vport=$(( vport + 1 ))
#mac=DE:AD:BE:EF:48:B4
name=slave${slaveid}
./runvm-daemon ${name}.qcow2 $ram $vcpu $tport $vport $mac $name
#for i in {1..$nports}
for (( i=1; i <$nvms; i++ ))
#for (( i=100; i <$nvms; i++ ))
do
tport=$(( tport + 1 )) # telnet port
vport=$(( vport + 1 )) # vnc port
# echo $i $tport $vport
# ./runvm-daemon slave${i}.qcow2 $ram $vcpu $tport $vport $mac
done
}
function migrate() {
tport=4446 # telnet port
mport=5446 # migration tcp port
vport=1 # vnc port
name=master
./ncmigrate ${name}.qcow2 $ram $vcpu $tport $vport $mport $masterpost $migspeed $name
#for i in {1..$nports}
#for (( vport=2; vport <=$nvms; vport++ ))
#for (( i=100; i <$nvms; i++ ))
for (( i=1; i <$nvms; i++ ))
do
tport=$(( tport + 1 ))
vport=$(( vport + 1 ))
mport=$(( mport + 1 ))
name=slave$i
echo $i $tport $vport $mport
./ncmigrate $name.qcow2 $ram $vcpu $tport $vport $mport $postcopy $migspeed $name
done
# ./ncmigrate slave2.qcow2 $ram $vcpu 4448 3 5448 $postcopy $migspeed
}
function check() {
miglog=$prefix.log
migtxt=$prefix.mig
rm -rf $miglog
#while [ $remain -gt 0 ];
while [ 1 ];
do
#remain=${#ports[@]}
#remain=$nports
remain=$nvms
#for port in ${ports[@]};
for (( port=4446; port <4446 + $nvms; port++ ))
do
info=`./bin/checkstatus localhost $port`
if [[ -z $info ]]; then
(( remain -- ))
continue
fi
status=`echo "$info" | grep -a complete | awk '{print $3}'`
#echo $status
if [[ $status == *completed* ]]; then
echo $port
echo "$info"
echo $info >> $miglog
./bin/stopvm localhost $port
#./stopvm $target $port
(( remain -- ))
continue
fi
# ./checkstatus $target $port
done
echo remaining: $remain
if [ $remain -le 0 ]; then
break
fi
sleep $sleeptime
done
# convert mac format to unix
tr '\r' '\n' < $miglog > $migtxt
}
function finish() {
for port in ${ports[@]};
do
echo $port
./bin/stopvm localhost $port
# ./stopvm $target $port
done
}
# average cpu usage since the last measurement
function cpusage() {
CPU=(`grep '^cpu ' /proc/stat`) # Get the total CPU statistics.
unset CPU[0] # Discard the "cpu" prefix.
IDLE=${CPU[4]} # Get the idle CPU time.
# Calculate the total CPU time.
TOTAL=0
for VALUE in "${CPU[@]}"; do
let "TOTAL=$TOTAL+$VALUE"
done
# Calculate the CPU usage since we last checked.
let "DIFF_IDLE=${IDLE}-${PREV_IDLE}"
let "DIFF_TOTAL=${TOTAL}-${PREV_TOTAL}"
let "DIFF_USAGE=(1000*(${DIFF_TOTAL}-${DIFF_IDLE})/${DIFF_TOTAL}+5)/10"
#echo -e "$DIFF_USAGE"
echo -e "CPU: $DIFF_USAGE %"
#echo -e "\rCPU: $DIFF_USAGE % \b\b"
# Remember the total and idle CPU times for the next check.
PREV_TOTAL="$TOTAL"
PREV_IDLE="$IDLE"
}
function iperftest() {
logsave 1vm-r1.iperf iperf -c c11node10 -f M -t 30
}
function download() {
min=3min
wget -O $prefix.src.net.png "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=c11node9&s=by+name&g=network_report"
wget -O $prefix.src.net.csv "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=c11node9&s=by+name&g=network_report&csv=1"
wget -O $prefix.src.cpu.png "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=c11node9&s=by+name&g=cpu_report"
wget -O $prefix.src.cpu.csv "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=c11node9&s=by+name&g=cpu_report&csv=1"
wget -O $prefix.dest.net.png "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${target}&s=by+name&g=network_report"
wget -O $prefix.dest.net.csv "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${target}&s=by+name&g=network_report&csv=1"
wget -O $prefix.dest.cpu.png "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${target}&s=by+name&g=cpu_report"
wget -O $prefix.dest.cpu.csv "http://10.244.36.20/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${target}&s=by+name&g=cpu_report&csv=1"
for node in master slave1 slave2 slave3
do
for resource in cpu network
do
#for filetype in png csv
#do
wget -O $prefix.$node.$resource.png "http://${ganglia}/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${node}&s=by+name&g=${resource}_report"
wget -O $prefix.$node.$resource.csv "http://${ganglia}/ganglia/graph.php?r=${min}&z=medium&c=Hadoop&h=${node}&s=by+name&g=${resource}_report&csv=1"
#done
done
done
}
function migratecluster() {
dstatfile=$prefix.src.dstat
srccsv=$dstatfile.csv
dstatdest=$prefix.dest.dstat
destcsv=$dstatdest.csv
dstatrouter=$prefix.router.dstat
routercsv=$dstatrouter.csv
dstatcmd="dstat -cnmd -N eth0,eth1,total --noheaders -o "
#dstat -cmdngy -N eth0,eth1,total --noheaders > $dstatfile &
$dstatcmd $srccsv > $dstatfile &
#ssh $target "dstat -cmdngy -N eth0,eth1,total --noheaders" > $dstatdest &
ssh $target mkdir -p $logdir
ssh $target $dstatcmd $destcsv > $dstatdest &
#ssh $target "$dstatcmd $dstatdest" &
ssh $router mkdir -p $logdir
ssh $router $dstatcmd $routercsv > $dstatrouter &
# sleep $preptime
migrate
check
# stop dstat
pgrep -fl dstat| awk '{print $1}' | xargs kill -9
ssh $target "pgrep -fl dstat| awk '{print $1}' | xargs kill -9"
# delete the first 5 lines
#sed -i '1,5d' $dstatfile
download
#ssh $target mkdir -p $logdir
#scp $target:$destcsv $prefix
#scp $router:$routercsv $prefix
# plot host cpu/net usage
# fix to add both send/receive
plotcpu="./plotcpu"
plotnet="./plotnet"
#$plotcpu $dstatfile
#$plotnet $dstatfile
#$plotcpu $dstatdest
#$plotnet $dstatdest
}
cpusage
#startcluster
migratecluster
#migratecluster > migrate.log
#finish
cpusage