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