9bbcf9848ae81ace2867c3e2d84b5b54670e5e90
[IRC.git] / Robust / src / Benchmarks / Recovery / runjava.sh
1 # !/bin/sh
2
3 # Usage
4 #
5 # ./runjava.sh <num_machine>
6 #
7
8 #set -x
9
10 BASEDIR=`pwd`
11 RECOVERYDIR='recovery'
12 JAVASINGLEDIR='java'
13 WAITTIME=180
14 KILLDELAY=6
15 LOGDIR=~/research/Robust/src/Benchmarks/Recovery/runlog
16 DSTMDIR=${HOME}/research/Robust/src/Benchmarks/Prefetch/config
17 MACHINELIST='dc-1.calit2.uci.edu dc-2.calit2.uci.edu dc-3.calit2.uci.edu dc-4.calit2.uci.edu dc-5.calit2.uci.edu dc-6.calit2.uci.edu dc-7.calit2.uci.edu dc-8.calit2.uci.edu'
18 USER='adash'
19
20 # 0 mean new test 
21 # 1~8 machine id to be killed
22
23 ## Sequential Machine failure order ######
24 ORDER=( 0 1 3 5 7 8 2    
25         0 1 2 3 4 5 6 
26         0 1 8 4 6 3 7 
27         0 8 7 3 6 5 4
28         0 7 4 6 8 1 2 
29         0 7 5 6 3 8 2 );
30
31 #ORDER=( 0 7 5 6 3 8 2 );
32
33 #
34 # killClients <fileName> <# of machines>
35 function killclients {
36   k=1;
37   fileName=$1
38   while [ $k -le $2 ]; do
39     echo "killing dc-$k ${fileName}"
40     ssh dc-${k} pkill -u ${USER} -f ${fileName} 
41     k=`expr $k + 1`
42   done
43 }
44
45 # killClientsWith USR1 signal <fileName> <# of machines>
46 function killclientswithSignal {
47   k=1;
48   fileName=$1
49   while [ $k -le $2 ]; do
50     echo "killing dc-$k ${fileName}"
51     ssh dc-${k} killall -USR1 ${fileName} 
52     k=`expr $k + 1`
53   done
54 }
55
56 # killonemachine <Benchmark file name> <machine_num>
57 function killonemachine {
58   fileName=$1
59   let "machine= $2";
60   echo "killing dc-$machine ${fileName}";
61   #ssh dc-${machine} pkill -u ${USER} -f ${fileName}
62   ssh dc-${machine} killall -USR1 ${fileName} 
63 }
64
65 # runmachines <log filename>
66 function runMachines {
67   echo "Running on ${NUM_MACHINE} machines ... "
68   
69   # Start machines
70   echo "Running machines"
71   let "k= $NUM_MACHINE"
72   if [ $k == 16 ]; then
73     k=8;
74   fi
75   
76   DIR=`echo ${BASEDIR}\/${BM_DIR}\/${RECOVERYDIR}`;
77   echo "DIR = $DIR";
78
79   echo $BM_NAME
80  
81   # Run machines
82   while [ $k -gt 1 ]; do
83     echo "SSH into dc-${k}"
84     ssh dc-${k} 'cd '$DIR'; ./'$BM_NAME'.bin '>> log'-'$k 2>&1 &
85     k=`expr $k - 1`
86     sleep 1
87   done
88   sleep 2
89   echo "Running master machine ... "
90   echo "ssh dc-1 cd $DIR'; ./$BM_NAME.bin master $NUM_MACHINE $BM_ARGS";
91   ssh dc-1 'cd '$DIR'; ./'$BM_NAME'.bin master '$NUM_MACHINE $BM_ARGS >> log'-1' 2>&1 &
92 }
93
94 ########### Normal execution
95 #  runNormalTest $NUM_MACHINES 1 
96 function runNormalTest {
97 # Run java version
98 # j=1;
99   BM_DIR=${BM_NAME}
100   fName="$BM_NAME.bin";
101   echo ${BM_DIR}
102   cd ${BM_DIR}
103
104
105   NUMM=$NUM_MACHINE;
106   if [ $NUM_MACHINE == 16 ]; then
107     NUMM=8;
108   fi
109
110   tt=1;
111   while [ $tt -le $NUM_MACHINE ]; do
112     echo "------------------------------- Normal Test $1 ----------------------------" >> log-$tt
113     tt=`expr $tt + 1`
114   done
115   
116 # run test
117   runMachines log
118   
119   sleep $WAITTIME
120   killclientswithSignal $fName 8
121 #killclients $fName 8
122   sleep 10
123   cd -
124 }
125
126 ########### Sequential Failure case ##########
127 function runSequentialFailureTest {
128 # Run java version
129 # j=1;
130   BM_DIR=${BM_NAME}
131   fName="$BM_NAME.bin";
132   cd ${BM_DIR}
133
134   test_iter=1;
135
136   for k in ${ORDER[@]}
137   do
138     if [ $k -eq 0 ]; then         # if k = 0, it is a new test
139       if [ $test_iter -ne 1 ]; then
140         sleep $WAITTIME           # wait the end of execution
141 #killclients $fName 8   # kill alive machines
142         killclientswithSignal $fName 8  #kill machines when there is more than 1 order
143         outputIter=0;
144         for outputIter in 1 2 3 4 5 6 7 8
145         do
146           echo "----------------------------------------------------------------------------------" >> log-$outputIter
147         done
148       fi
149
150       outputIter=0;
151       for outputIter in 1 2 3 4 5 6 7 8
152       do
153         echo "------------------------------- Sequential Failure Test $test_iter ----------------------------" >> log-$outputIter
154       done
155       echo "------------------------------- Sequential Failure Test $test_iter ----------------------------"
156       runMachines log   
157       sleep 10           # wait until all machine run
158       test_iter=`expr $test_iter + 1`
159     else                 # if k != 0, time to kill machines!
160       echo "------------------------ dc-$k is killed ------------------------" >> log-$k
161       echo "------------------------ dc-$k is killed ------------------------"
162       killonemachine $fName $k
163       
164       let "delay= $RANDOM % $KILLDELAY + 8"
165       sleep $delay
166     fi 
167   done
168
169   sleep $WAITTIME           # wait the end of execution
170 #  killclients $fName 8   # kill alive machines
171   killclientswithSignal $fName 8 #kill machines when finished processing everything in ORDER{ }
172   sleep 10
173  cd -
174 }
175
176 ####### Single machine failure Case ############
177 function runSingleFailureTest {
178   BM_DIR=${BM_NAME}
179   fName="$BM_NAME.bin";
180   cd ${BM_DIR}
181
182   test_iter=1;
183
184 SINGLE_ORDER=( 1 8 4 6 3 2 7 5 );
185 #SINGLE_ORDER=( 8 );
186
187
188   for machinename in ${SINGLE_ORDER[@]}
189   do
190     outputIter=0;
191     for outputIter in 1 2 3 4 5 6 7 8
192     do
193       echo "------------------------------- Single Failure Test $test_iter ----------------------------" >> log-$outputIter
194     done
195     echo "------------------------------- Single Failure Test $test_iter ----------------------------"
196     runMachines log   
197     sleep 10           # wait until all machine run
198     test_iter=`expr $test_iter + 1`
199     echo "------------------------ dc-$machinename is killed ------------------------" >> log-$k
200     echo "------------------------ dc-$machinename is killed ------------------------"
201     killonemachine $fName $machinename
202     sleep $WAITTIME           # wait till the end of execution
203     killclientswithSignal $fName 8  #kill rest of the alive machines
204 # Insert Randowm delay 
205       let "delay= $RANDOM % $KILLDELAY + 4"
206       sleep $delay
207   done
208  cd -
209 }
210
211 ###
212 ###runRecovery <num iterations> <num machines> <recovery file name>
213 ###
214 function runRecovery {
215   i=1;
216   DIR=`echo ${BASEDIR}\/${BM_NAME}\/${RECOVERYDIR}`;
217   cd ${DIR}
218   fName="$BM_NAME.bin";
219   HOSTNAME=`hostname`
220   while [ $i -le $1 ]; do
221     tt=1;
222     while [ $tt -le $2 ]; do
223       echo "------------------------------- running Recovery on $2 machines for iter=$i ----------------------------" >> log-$tt
224       tt=`expr $tt + 1`
225     done
226
227     #select the correct dstm config file
228     rm dstm.conf
229     if [ $2 -eq 2 ]; then 
230       ln -s ${DSTMDIR}/dstm_2.conf dstm.conf
231     fi
232     if [ $2 -eq 3 ]; then 
233       ln -s ${DSTMDIR}/dstm_3.conf dstm.conf
234     fi
235     if [ $2 -eq 4 ]; then 
236       ln -s ${DSTMDIR}/dstm_4.conf dstm.conf
237     fi
238     if [ $2 -eq 5 ]; then 
239       ln -s ${DSTMDIR}/dstm_5.conf dstm.conf
240     fi
241     if [ $2 -eq 6 ]; then 
242       ln -s ${DSTMDIR}/dstm_6.conf dstm.conf
243     fi
244     if [ $2 -eq 7 ]; then 
245       ln -s ${DSTMDIR}/dstm_7.conf dstm.conf
246     fi
247     if [ $2 -eq 8 ]; then 
248       ln -s ${DSTMDIR}/dstm_8.conf dstm.conf
249     fi
250
251     #Start machines
252     let "k= $2"
253     while [ $k -gt 1 ]; do
254       echo "SSH into dc-${k}"
255       ssh dc-${k} 'cd '$DIR'; ./'$BM_NAME'.bin '>> log'-'$k 2>&1 &
256       k=`expr $k - 1`
257       sleep 1
258     done
259     sleep 2
260     #Start master
261     echo "Running master machine ..."
262     ssh dc-1 'cd '$DIR'; ./'$BM_NAME'.bin master '$2 $BM_ARGS >> log'-1' 2>&1 &
263     sleep $WAITTIME
264     echo "Terminating ... "
265     killclientswithSignal $fName $2
266     sleep 5
267     i=`expr $i + 1`
268   done
269   cd -
270 }
271
272 ###
273 ###runDSM <num iterations> <num machines> <dsm file name>
274 ###
275 function runDSM {
276   i=1;
277   DIR=`echo ${BASEDIR}\/${BM_NAME}\/${RECOVERYDIR}`;
278   cd ${DIR}
279   fName="$BM_DSM.bin";
280   HOSTNAME=`hostname`
281   while [ $i -le $1 ]; do
282     tt=1;
283     while [ $tt -le $2 ]; do
284       echo "------------------------------- running DSM on $2 machines for iter=$i ----------------------------" >> log-$tt
285       tt=`expr $tt + 1`
286     done
287
288     #select the correct dstm config file
289     rm dstm.conf
290     if [ $2 -eq 2 ]; then 
291       ln -s ${DSTMDIR}/dstm_2.conf dstm.conf
292     fi
293     if [ $2 -eq 3 ]; then 
294       ln -s ${DSTMDIR}/dstm_3.conf dstm.conf
295     fi
296     if [ $2 -eq 4 ]; then 
297       ln -s ${DSTMDIR}/dstm_4.conf dstm.conf
298     fi
299     if [ $2 -eq 5 ]; then 
300       ln -s ${DSTMDIR}/dstm_5.conf dstm.conf
301     fi
302     if [ $2 -eq 6 ]; then 
303       ln -s ${DSTMDIR}/dstm_6.conf dstm.conf
304     fi
305     if [ $2 -eq 7 ]; then 
306       ln -s ${DSTMDIR}/dstm_7.conf dstm.conf
307     fi
308     if [ $2 -eq 8 ]; then 
309       ln -s ${DSTMDIR}/dstm_8.conf dstm.conf
310     fi
311
312     #Start machines
313     let "k= $2"
314     while [ $k -gt 1 ]; do
315       echo "SSH into dc-${k}"
316       ssh dc-${k} 'cd '$DIR'; ./'$BM_DSM'.bin '>> log'-'$k 2>&1 &
317       k=`expr $k - 1`
318       sleep 3
319     done
320     sleep 6
321     #Start master
322     echo "Running master machine ..."
323     ssh dc-1 'cd '$DIR'; ./'$BM_DSM'.bin master '$2 $BM_ARGS >> log'-1' 2>&1 &
324     sleep $WAITTIME
325     echo "Terminating ... "
326     killclientswithSignal $fName $2
327     sleep 5
328     i=`expr $i + 1`
329   done
330   cd -
331 }
332
333 function testcase {
334   nummachines=$1
335   shift
336   line=$@
337   BM_NAME=`echo $line | cut -f1 -d":"`
338   BM_ARGS=`echo $line | cut -f2 -d":"`
339
340
341   # Setup for remote machine
342   echo "BM_NAME='$BM_NAME'" 
343   echo "BM_ARGS='$BM_ARGS'" 
344   BM_DSM=${BM_NAME}DSM
345
346   fileName=${BM_NAME}.bin
347
348   # terminate if it doesn't have parameter
349   let "NUM_MACHINE= $nummachines + 0";
350
351   echo "====================================== Normal Test =============================="
352   runNormalTest $NUM_MACHINES 1 
353   echo "================================================================================"
354
355 #  echo "====================================== Single Failure Test ============================="
356 #  runSingleFailureTest $NUM_MACHINES
357 #  echo "================================================================================="
358
359 #  echo "====================================== Sequential Failure Test ============================="
360 #  runSequentialFailureTest $NUM_MACHINES
361 #  echo "================================================================================="
362
363   
364 #  echo "=============== Running javasingle for ${BM_NAME} on 1 machines ================="
365 #  javasingle 1 ${BM_NAME}
366 #  cd $TOPDIR
367 #  echo "================================================================================="
368
369 # echo "=============== Running recoverysingle for ${BM_NAME} on 1 machines ================="
370 #  recoverysingle 1 ${BM_NAME}
371 #  cd $TOPDIR
372 #  echo "================================================================================="
373
374 #  echo "=============== Running dsmsingle for ${BM_NAME} on 1 machines ================="
375 #  dsmsingle 1 ${BM_DSM}
376 #  cd $TOPDIR
377 #  echo "================================================================================="
378
379 #  echo "====================================== Recovery Execution Time ============================="
380 #  for count in 2 4 8
381 #  do
382 #    echo "------- Running $count threads $BM_NAME recovery on $count machines -----"
383 #    runRecovery 1 $count ${BM_NAME}
384 #  done
385 #  echo "================================================================================="
386
387 #  echo "====================================== DSM Execution Time ============================="
388 #  for count in 2 4 8
389 #  do
390 #    echo "------- Running $count threads $BM_NAME dsm on $count machines -----"
391 #    runDSM 1 $count $BM_DSM
392 #  done
393 #  echo "================================================================================="
394
395 }
396
397 function javasingle {
398
399   DIR=`echo ${BASEDIR}\/${2}\/${JAVASINGLEDIR}`;
400   cd $DIR
401   echo ${BM_ARGS}
402   i=0;
403   echo "ssh dc-1 cd $DIR'; ./${2}.bin 1 ${BM_ARGS}";
404   while [ $i -lt $1 ]; do
405     /usr/bin/time -f "%e" ./${2}.bin 1 ${BM_ARGS} 2> ${DIR}/tmp
406     cat ${DIR}/tmp >> ${LOGDIR}/${2}_javasingle.txt
407     sleep 2
408     i=`expr $i + 1`
409   done
410 }
411
412 function recoverysingle {
413   DIR=`echo ${BASEDIR}\/${2}\/${RECOVERYDIR}`;
414   cd $DIR
415   echo ${BM_ARGS}
416   rm dstm.conf
417   ln -s ${DSTMDIR}/dstm_1.conf dstm.conf
418   cd `pwd`
419   i=0;
420   fName="${2}.bin";
421   while [ $i -lt $1 ]; do
422     echo "Running master machine ... "
423     echo "ssh dc-1 cd $DIR'; ./${2}.bin master 1 ${BM_ARGS}";
424     ssh dc-1 'cd '$DIR'; ./'${2}'.bin master '1 ${BM_ARGS} >> ${LOGDIR}/${2}_recoverysingle.txt 2>&1 &
425     echo "Start waiting"
426     sleep $WAITTIME
427     echo "killing dc-1 ${fName}"
428     pkill -u ${USER} -f ${fName} 
429     i=`expr $i + 1`
430   done
431 }
432
433 function dsmsingle {
434   DIR=`echo ${BASEDIR}\/${BM_NAME}\/${RECOVERYDIR}`;
435   cd $DIR
436   echo ${BM_ARGS}
437   rm dstm.conf
438   ln -s ${DSTMDIR}/dstm_1.conf dstm.conf
439   cd `pwd`
440   i=0;
441   fName="${2}.bin";
442   while [ $i -lt $1 ]; do
443     echo "Running master machine ... "
444     echo "ssh dc-1 cd $DIR'; ./${2}.bin master 1 ${BM_ARGS}";
445     ssh dc-1 'cd '$DIR'; ./'${2}'.bin master '1 ${BM_ARGS} >> ${LOGDIR}/${BM_NAME}_dsmsingle.txt 2>&1 &
446     echo "Start waiting"
447     sleep $WAITTIME
448     echo "killing dc-1 ${fName}"
449     pkill -u ${USER} -f ${fName} 
450     i=`expr $i + 1`
451   done
452 }
453
454 echo "---------- Starting Benchmarks ----------"
455 nmach=$1
456 #source bm_args.txt
457 source bm_args_16threads.txt
458 echo "----------- done ------------"