1
1
#! /bin/bash
2
2
3
- rs =(1)
4
- cs =(1)
5
- w =10
6
- d =10
3
+ rpcs =(1)
4
+ conns =(1)
5
+ warmup =10
6
+ dur =10
7
7
reqs=(1)
8
8
resps=(1)
9
9
rpc_types=(unary)
10
10
11
- # idx[0] = idx value for rs
12
- # idx[1] = idx value for cs
11
+ # idx[0] = idx value for rpcs
12
+ # idx[1] = idx value for conns
13
13
# idx[2] = idx value for reqs
14
14
# idx[3] = idx value for resps
15
15
# idx[4] = idx value for rpc_types
@@ -18,33 +18,39 @@ idx_max=(1 1 1 1 1)
18
18
19
19
inc ()
20
20
{
21
- for i in $( seq $(( ${# idx[@]} - 1 )) -1 0)
22
- do
21
+ for i in $( seq $(( ${# idx[@]} - 1 )) -1 0) ; do
23
22
idx[${i} ]=$(( ${idx[${i}]} + 1 ))
24
23
if [ ${idx[${i}]} == ${idx_max[${i}]} ]; then
25
24
idx[${i} ]=0
26
25
else
27
26
break
28
27
fi
29
28
done
30
- return=1
29
+ local fin
30
+ fin=1
31
31
# Check to see if we have looped back to the beginning.
32
32
for v in ${idx[@]} ; do
33
- if [ ${v} == 0 ]; then
34
- return=$(( ${return} * 1 ))
35
- else
36
- return=$(( ${return} * 0 ))
33
+ if [ ${v} != 0 ]; then
34
+ fin=0
35
+ break
37
36
fi
38
37
done
39
- if [ ${return } == 1 ]; then
40
- rm -Rf ${out_dir}
41
- exit 0
38
+ if [ ${fin } == 1 ]; then
39
+ rm -Rf ${out_dir}
40
+ clean_and_die 0
42
41
fi
43
42
}
44
43
44
+ clean_and_die () {
45
+ rm -Rf ${out_dir}
46
+ exit $1
47
+ }
48
+
45
49
run (){
46
- nr=${rs[${idx[0]} ]}
47
- nc=${cs[${idx[1]} ]}
50
+ local nr
51
+ nr=${rpcs[${idx[0]} ]}
52
+ local nc
53
+ nc=${conns[${idx[1]} ]}
48
54
req_sz=${reqs[${idx[2]} ]}
49
55
resp_sz=${resps[${idx[3]} ]}
50
56
r_type=${rpc_types[${idx[4]} ]}
63
69
server_pid=$( echo $! )
64
70
65
71
# Launch the client
66
- ${out_dir} /client --port=${port} --d=${d } --w=${w } --r=${nr} --c=${nc} --req=${req_sz} --resp=${resp_sz} --rpc_type=${r_type} --test_name=" client_" ${test_name}
72
+ ${out_dir} /client --port=${port} --d=${dur } --w=${warmup } --r=${nr} --c=${nc} --req=${req_sz} --resp=${resp_sz} --rpc_type=${r_type} --test_name=" client_" ${test_name}
67
73
client_status=$( echo $? )
68
74
69
75
kill ${server_pid}
@@ -77,101 +83,75 @@ run(){
77
83
if [ ${delta} == 10 ]; then
78
84
echo " Continuous 10 failed runs. Exiting now."
79
85
rm -Rf ${out_dir}
80
- exit 1
86
+ clean_and_die 1
81
87
fi
82
88
done
83
89
84
90
}
85
91
86
- while test $# -gt 0; do
92
+ set_param (){
93
+ local argname=$1
94
+ shift
95
+ local idx=$1
96
+ shift
97
+ if [ $# -eq 0 ]; then
98
+ echo " ${argname} not specified"
99
+ exit 1
100
+ fi
101
+ PARAM=($( echo $1 | sed ' s/,/ /g' ) )
102
+ if [ ${idx} -lt 0 ]; then
103
+ return
104
+ fi
105
+ idx_max[${idx} ]=${# PARAM[@]}
106
+ }
107
+
108
+ while [ $# -gt 0 ]; do
87
109
case " $1 " in
88
110
-r)
89
111
shift
90
- if test $# -gt 0; then
91
- rs=($( echo $1 | sed ' s/,/ /g' ) )
92
- idx_max[0]=${# rs[@]}
93
- else
94
- echo " number of rpcs not specified"
95
- exit 1
96
- fi
112
+ set_param " number of rpcs" 0 $1
113
+ rpcs=(${PARAM[@]} )
97
114
shift
98
115
;;
99
116
-c)
100
117
shift
101
- if test $# -gt 0; then
102
- cs=($( echo $1 | sed ' s/,/ /g' ) )
103
- idx_max[1]=${# cs[@]}
104
- else
105
- echo " number of connections not specified"
106
- exit 1
107
- fi
118
+ set_param " number of connections" 1 $1
119
+ conns=(${PARAM[@]} )
108
120
shift
109
121
;;
110
122
-w)
111
123
shift
112
- if test $# -gt 0; then
113
- w=$1
114
- else
115
- echo " warm-up period not specified"
116
- exit 1
117
- fi
124
+ set_param " warm-up period" -1 $1
125
+ warmup=${PARAM}
118
126
shift
119
127
;;
120
128
-d)
121
129
shift
122
- if test $# -gt 0; then
123
- d=$1
124
- else
125
- echo " duration not specified"
126
- exit 1
127
- fi
130
+ set_param " duration" -1 $1
131
+ dur=${PARAM}
128
132
shift
129
133
;;
130
134
-req)
131
135
shift
132
- if test $# -gt 0; then
133
- reqs=($( echo $1 | sed ' s/,/ /g' ) )
134
- idx_max[2]=${# reqs[@]}
135
- else
136
- echo " request size not specified"
137
- exit 1
138
- fi
136
+ set_param " request size" 2 $1
137
+ reqs=(${PARAM[@]} )
139
138
shift
140
139
;;
141
140
-resp)
142
141
shift
143
- if test $# -gt 0; then
144
- resps=($( echo $1 | sed ' s/,/ /g' ) )
145
- idx_max[3]=${# resps[@]}
146
- else
147
- echo " response size not specified"
148
- exit 1
149
- fi
142
+ set_param " response size" 3 $1
143
+ resps=(${PARAM[@]} )
150
144
shift
151
145
;;
152
146
-rpc_type)
153
147
shift
154
- if test $# -gt 0; then
155
- rpc_types=($( echo $1 | sed ' s/,/ /g' ) )
156
- idx_max[4]=${# rpc_types[@]}
157
- for val in ${rpc_types[@]} ; do
158
- case " ${val} " in
159
- " unary" |" streaming" );;
160
- * ) echo " Incorrect value for rpc_type"
161
- exit 1
162
- ;;
163
- esac
164
-
165
- done
166
- else
167
- echo " rpc type not specified not specified"
168
- exit 1
169
- fi
148
+ set_param " rpc type" 4 $1
149
+ rpc_types=(${PARAM[@]} )
170
150
shift
171
151
;;
172
152
-h|--help)
173
153
echo " Following are valid options:"
174
- echo " "
154
+ echo
175
155
echo " -h, --help show brief help"
176
156
echo " -w warm-up duration in seconds, default value is 10"
177
157
echo " -d benchmark duration in seconds, default value is 60"
@@ -185,7 +165,7 @@ while test $# -gt 0; do
185
165
echo " -rpc_type valid values are unary|streaming, default is unary"
186
166
;;
187
167
* )
188
- echo " Incorrect option"
168
+ echo " Incorrect option $1 "
189
169
exit 1
190
170
;;
191
171
esac
@@ -196,7 +176,7 @@ out_dir=$(mktemp -d oss_benchXXX)
196
176
197
177
go build -o ${out_dir} /server $GOPATH /src/google.golang.org/grpc/benchmark/server/main.go && go build -o ${out_dir} /client $GOPATH /src/google.golang.org/grpc/benchmark/client/main.go
198
178
if [ $? != 0 ]; then
199
- exit 1
179
+ clean_and_die 1
200
180
fi
201
181
202
182
0 commit comments