-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhey-ho.sh
executable file
Β·218 lines (203 loc) Β· 5.99 KB
/
hey-ho.sh
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
#!/bin/bash
############################################################
# Help #
############################################################
show_help()
{
echo "Deploys any number of Pods sending load to each other, for a given amount of time."
echo
echo "Syntax: hey-ho [options]"
echo "Options:"
echo "-c Cleanup namespaces and exit. Combine with -n to set the number of namespaces to delete."
echo "-n X Number of namespaces. Default: 1"
echo "-d X Number of deployments per namespace. Default: 5"
echo "-r X Number of replicas per deployment. Default: 2"
echo "-w X Number of workers per replica. Default: 50"
echo "-z time Load sending duration, e.g. 10s or 3m. Default: 30s"
echo "-q qps Rate limit, in query per seconds. 0 means no limit. Default: 200"
echo "-g name Namespace name. Default: gallery"
echo "-t target Single target mode. Default: disabled"
echo "-u uid User ID to use for security context. Default: disabled"
echo "-p Predictable mode (no random target assignment). Default: disabled"
echo "-y Non-interactive mode, reply 'yes' to prompt. Default: disabled"
echo "-b Bip when results are received"
echo "-f Fake / dry run. Default: disabled"
echo "-h Print this help."
echo
}
delete_namespaces () {
for (( n=0; n<$1; n++ ))
do
kubectl delete namespace ${namespace}$n
done
}
namespace="gallery"
namespaces=1
deployments=5
replicas=2
workers=50
duration=30s
qps=200
run_as_user=""
while getopts "h?cn:d:r:w:z:q:g:t:u:pybf" opt; do
case $opt in
h|\?)
show_help
exit 0
;;
c) cleanup=1 ;;
n) namespaces=$(( OPTARG )) ;;
d) deployments=$(( OPTARG )) ;;
r) replicas=$(( OPTARG )) ;;
w) workers=$(( OPTARG )) ;;
z) duration=$OPTARG ;;
q) qps=$(( OPTARG )) ;;
g) namespace=$OPTARG ;;
t) single_target=$OPTARG ;;
u) run_as_user=$OPTARG ;;
p) predictable=1 ;;
y) yes=1 ;;
b) bipcmd="printf \\a" ;;
f) fake=1 ;;
*) echo 'error' >&2
exit 1
esac
done
if [[ $cleanup -eq 1 ]]; then
delete_namespaces ${namespaces}
exit 0
fi
next_target=0
nb_targets=$(($deployments * $namespaces))
inc_target () {
if [[ ${predictable} -eq 1 ]]; then
next_target=$((($next_target+1) % $nb_targets))
else
next_target=$(($RANDOM % $nb_targets))
fi
}
target () {
ns=$(($next_target / $deployments))
dep=$(($next_target % $deployments))
echo "http://hey-ho-${dep}.${namespace}${ns}:8080"
}
export REPLICAS=${replicas}
export RUN_AS_USER=${run_as_user}
HEY_ARGS="-c ${workers} -z ${duration}"
if [[ ${qps} -ne 0 ]]; then
HEY_ARGS+=" -q ${qps}"
fi
echo "πͺ You asked creation of a total of ${namespaces} namespaces, $(( namespaces * deployments )) deployments, $(( namespaces * deployments * replicas )) pods, $(( namespaces * deployments * replicas * workers )) workers."
echo " β³ Running for ${duration}"
if [[ ${qps} -ne 0 ]]; then
if [[ ${qps} -le 50 ]]; then
animal="π"
elif [[ ${qps} -le 100 ]]; then
animal="π"
elif [[ ${qps} -le 500 ]]; then
animal="πͺ"
else
animal="π"
fi
echo " ${animal} Rate-limited at ${qps} queries per second"
else
echo " β‘ Without any rate-limit"
fi
if [[ "${single_target}" == "" ]]; then
echo " πΈοΈ Target each other"
else
echo " πΉ Single target: ${single_target}"
fi
if [[ ${predictable} -eq 1 ]]; then
echo " π€ Peers assigned in a predictable way"
else
echo " π§ Peers assigned randomly"
fi
if [[ "${bipcmd}" == "" ]]; then
echo " π No bip when finished"
else
echo " π Bip when finished"
fi
if [[ "${run_as_user}" == "" ]]; then
echo " π€ No specific user"
else
echo " π Run as user ${run_as_user}"
fi
echo "------"
echo " π 'hey' command arguments: ${HEY_ARGS}"
echo "------"
if [[ ${fake} -eq 1 ]]; then
echo " π Running in dry-run mode"
else
echo " π§ Running for real!"
fi
echo "------"
echo ""
if [[ ${yes} -ne 1 ]]; then
read -p "π Continue? [y/N] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 0
fi
fi
echo ""
# generate deployments
echo "Deploying pods"
for (( n=0; n<$namespaces; n++ ))
do
export NAMESPACE="${namespace}$n"
if [[ $fake -ne 1 ]]; then
kubectl create namespace ${NAMESPACE}
fi
for (( d=0; d<$deployments; d++ )); do
export NAME="hey-ho-$d"
if [[ $fake -eq 1 ]]; then
echo "DRY RUN - output:"
echo ""
envsubst < ./hey-ho-tpl.yaml
echo "---"
else
envsubst < ./hey-ho-tpl.yaml | kubectl apply -n ${NAMESPACE} -f -
fi
done
done
# wait until they're all ready
echo "Waiting pods availability..."
for (( n=0; n<$namespaces; n++ )); do
NAMESPACE="${namespace}$n"
for (( d=0; d<$deployments; d++ )); do
NAME="hey-ho-$d"
if [[ $fake -eq 1 ]]; then
echo " kubectl wait deployment ${NAME} -n ${NAMESPACE} --for condition=Available=True"
else
kubectl wait deployment ${NAME} -n ${NAMESPACE} --for condition=Available=True
fi
done
done
# start sending load
echo "Start sending load"
for (( n=0; n<$namespaces; n++ )); do
NAMESPACE="${namespace}$n"
for (( d=0; d<$deployments; d++ )); do
NAME="hey-ho-$d"
if [[ "$single_target" == "" ]]; then
inc_target
TARGET=$(target)
else
TARGET=$single_target
fi
if [[ $fake -eq 1 ]]; then
echo " pods= kubectl get pods -n ${NAMESPACE} -l app=${NAME} --no-headers -o custom-columns=':metadata.name' "
echo " For each pod, run:"
echo " { kubectl -n ${NAMESPACE} exec <pod name> -- /tmp/hey ${HEY_ARGS} ${TARGET}; date; ${bipcmd}; } &"
else
pods=`kubectl get pods -n ${NAMESPACE} -l app=${NAME} --no-headers -o custom-columns=":metadata.name"`
for pod in $pods; do
echo "Starting hey on pod ${pod} to target ${TARGET}"
{ kubectl -n ${NAMESPACE} exec ${pod} -- /tmp/hey ${HEY_ARGS} ${TARGET}; date; ${bipcmd}; } &
done
fi
done
done
echo "It's `date`, come back in ${duration} for results."