changes
[IRC.git] / Robust / src / Benchmarks / Recovery / runjava.sh
1 # !/bin/sh
2
3 # Usage
4 #
5 # ./runjava.sh <num_machine>
6 #
7
8 BASEDIR=`pwd`
9 RECOVERYDIR='recovery'
10 JAVASINGLEDIR='java'
11 WAITTIME=1200
12 KILLDELAY=20
13
14 # 0 mean new test 
15 # 1~8 machine id to be killed
16 ORDER=( 0 1 3 5 7 8 2    
17         0 1 2 3 4 5 6 
18         0 1 8 4 6 3 7 
19         0 8 7 3 6 5 4
20         0 7 4 6 8 1 2 );
21
22 # killClients <fileName> <# of machines>
23 function killclients {
24   i=1;
25   fileName=$1
26   while [ $i -le $2 ]; do
27     echo "killing dc-$i ${fileName}"
28     ssh dc-${i} pkill -u jihoonl -f ${fileName} 
29     i=`expr $i + 1`
30   done
31 }
32
33 # killonemachine <Benchmark file name> <machine_num>
34 function killonemachine {
35   fileName=$1
36   let "machine= $2";
37   echo "killing dc-$machine ${fileName}";
38   ssh dc-${machine} pkill -u jihoonl -f ${fileName}
39 }
40
41 # runmachines <log filename>
42 function runMachines {
43   echo "Running on ${NUM_MACHINE} machines ... "
44   
45   # Start machines
46   echo "Running machines"
47   let "k= $NUM_MACHINE"
48   
49   DIR=`echo ${BASEDIR}\/${BM_DIR}\/${RECOVERYDIR}`;
50   echo "DIR = $DIR";
51  
52   # Run machines
53   while [ $k -gt 1 ]; do
54     echo "SSH into dc-${k}"
55     ssh dc-${k} 'cd '$DIR'; ./'$BM_NAME'.bin '>> $1'-'$k 2>&1 &
56     k=`expr $k - 1`
57     sleep 1
58   done
59   echo "Running master machine ... "
60   echo "ssh dc-1 cd $DIR'; ./$BM_NAME.bin master $NUM_MACHINE $BM_ARGS";
61   ssh dc-1 'cd '$DIR'; ./'$BM_NAME'.bin master '$NUM_MACHINE $BM_ARGS >> $1'-1' 2>&1 &
62 }
63
64 ########### Normal execution
65 function runNormalTest {
66 # Run java version
67   j=1;
68   BM_DIR=${BM_NAME}
69   fName="$BM_NAME.bin";
70   echo ${BM_DIR}
71   cd ${BM_DIR}
72
73   tt=1;
74   while [ $tt -le $NUM_MACHINE ]; do
75     echo "------------------------------- Normal Test $1 ----------------------------" >> log-$tt
76     tt=`expr $tt + 1`
77   done
78   
79 # run test
80   runMachines log
81   
82   sleep $WAITTIME
83
84   killclients $fName 8
85   sleep 10
86   cd -
87 }
88
89 ########### Failure case
90 function runFailureTest {
91 # Run java version
92   j=1;
93   BM_DIR=${BM_NAME}
94   fName="$BM_NAME.bin";
95   cd ${BM_DIR}
96
97   test_iter=1;
98
99   for k in ${ORDER[@]}
100   do
101     if [ $k -eq 0 ]; then         # if k = 0, it is a new test
102       if [ $test_iter -ne 1 ]; then
103         sleep $WAITTIME           # wait the end of execution
104         killclients $fName 8   # kill alive machines
105         outputIter=0;
106         for outputIter in 1 2 3 4 5 6 7 8
107         do
108           echo "----------------------------------------------------------------------------------" >> log-$outputIter
109         done
110       fi
111
112       outputIter=0;
113       for outputIter in 1 2 3 4 5 6 7 8
114       do
115         echo "------------------------------- Failure Test $test_iter ----------------------------" >> log-$outputIter
116       done
117       echo "------------------------------- Failure Test $test_iter ----------------------------"
118       runMachines log   
119       sleep 10           # wait until all machine run
120       test_iter=`expr $test_iter + 1`
121     else                 # if k != 0, time to kill machines!
122       echo "------------------------ dc-$k is killed ------------------------" >> log-$k
123       echo "------------------------ dc-$k is killed ------------------------"
124       killonemachine $fName $k
125       
126       let "delay= $RANDOM % $KILLDELAY + 3"
127       sleep $delay
128     fi 
129   done
130
131   killclients $fName 8   # kill alive machines
132   sleep 10
133  cd -
134 }
135
136
137 function testcase {
138   nummachines=$1
139   shift
140   line=$@
141   BM_NAME=`echo $line | cut -f1 -d":"`
142   BM_ARGS=`echo $line | cut -f2 -d":"`
143
144
145   # Setup for remote machine
146   echo "BM_NAME='$BM_NAME'" 
147   echo "BM_ARGS='$BM_ARGS'" 
148
149   fileName=${BM_NAME}.bin
150
151   # terminate if it doesn't have parameter
152   let "NUM_MACHINE= $nummachines + 0";
153
154   echo "====================================== Normal Test =============================="
155   runNormalTest $NUM_MACHINES 1 
156   echo "================================================================================"
157
158   echo "====================================== Failure Test ============================="
159   runFailureTest $NUM_MACHINES
160   echo "================================================================================="
161 }
162
163
164 echo "---------- Starting Benchmarks ----------"
165 nmach=$1
166 source bm_args.txt
167 echo "----------- done ------------"