-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathrun_benchmark_job.sh
executable file
·325 lines (270 loc) · 10.5 KB
/
run_benchmark_job.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
# Copyright Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
WD=$(dirname "$0")
WD=$(cd "$WD"; pwd)
ROOT=$(dirname "$WD")
# Exit immediately for non zero status
set -e
# Check unset variables
set -u
# Print commands
set -x
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
# Boskos cluster related Env vars
# This is the config for postsubmit cluster.
export VALUES="${VALUES:-values-istio-postsubmit.yaml}"
# Check https://github.com/istio/test-infra/blob/master/boskos/configs.yaml
# for existing resources types
export RESOURCE_TYPE="${RESOURCE_TYPE:-gke-perf-preset}"
export PILOT_CLUSTER="${PILOT_CLUSTER:-}"
export USE_MASON_RESOURCE="${USE_MASON_RESOURCE:-False}"
export CLEAN_CLUSTERS="${CLEAN_CLUSTERS:-True}"
export OWNER="${OWNER:-perf-tests}"
export CREATE_CLUSTER="${CREATE_CLUSTER:-false}"
# Istio performance test related Env vars
export NAMESPACE=${NAMESPACE:-'twopods-istio'}
export PROMETHEUS_NAMESPACE=${PROMETHEUS_NAMESPACE:-'istio-prometheus'}
export ISTIO_INJECT=${ISTIO_INJECT:-true}
export DNS_DOMAIN="fake-dns.org"
export LOAD_GEN_TYPE=${LOAD_GEN_TYPE:-"fortio"}
export FORTIO_CLIENT_URL=""
export IOPS=${IOPS:-istioctl_profiles/default-overlay.yaml}
export ISTIO_RELEASE_VERSION="${ISTIO_RELEASE_VERSION:-}"
# For adding or modifying configurations, refer to perf/benchmark/README.md
export CONFIG_DIR=${CONFIG_DIR:-"${WD}/configs/istio"}
export PERF_TEST_CONFIGURATION=${PERF_TEST_CONFIGURATION:-"${WD}/configs/run_perf_test.conf"}
# For enabling fortio server ingress cert for testing with TLS
export FORTIO_SERVER_INGRESS_CERT_ENABLED="${FORTIO_SERVER_INGRESS_CERT_ENABLED:-false}"
# Other Env vars
export GCS_BUCKET=${GCS_BUCKET:-"istio-build/perf"}
export TRIALRUN=${TRIALRUN:-"False"}
CLEANUP_PIDS=()
# Step 1: setup/create cluster
if [[ "${CREATE_CLUSTER}" == "true" ]]; then
export KUBECONFIG="${WD}/tmp/kube.yaml"
pushd "${ROOT}/istio-install"
./cluster.sh create
popd
else
# shellcheck disable=SC1090,SC1091
source "${ROOT}/../bin/setup_cluster.sh"
setup_e2e_cluster
fi
# Step 2: install Istio
# Setup release info
BRANCH="latest"
if [[ "${GIT_BRANCH}" != "master" ]];then
BRANCH_NUM=$(echo "$GIT_BRANCH" | cut -f2 -d-)
BRANCH="${BRANCH_NUM}-dev"
fi
pushd "${ROOT}/istio-install"
if [[ ${ISTIO_RELEASE_VERSION} ]]; then
INSTALL_VERSION=${ISTIO_RELEASE_VERSION}
echo "Setup istio release: ${INSTALL_VERSION}"
VERSION=${INSTALL_VERSION} ./setup_istio.sh
else
# Different branch tag resides in dev release directory like /latest, /1.4-dev, /1.5-dev etc.
INSTALL_VERSION=$(curl "https://storage.googleapis.com/istio-build/dev/${BRANCH}")
echo "Setup istio release: ${INSTALL_VERSION}"
DEV_VERSION=${INSTALL_VERSION} ./setup_istio.sh
fi
popd
# Step 3: setup Istio performance test
pushd "${WD}"
export ISTIO_INJECT="true"
./setup_test.sh
popd
# Step 4: install Python dependencies
# Install pipenv
if [[ $(command -v pipenv) == "" ]];then
apt-get update && apt-get -y install python3-pip
pip3 install pipenv
fi
# Install dependencies
cd "${WD}"
pipenv install
# Step 5: setup perf data local output directory
dt=$(date +'%Y%m%d')
# Current output dir should be like: 20200523_nighthawk_master_1.7-alpha.f19fb40b777e357b605e85c04fb871578592ad1e
export OUTPUT_DIR="${dt}_${LOAD_GEN_TYPE}_${GIT_BRANCH}_${INSTALL_VERSION}"
LOCAL_OUTPUT_DIR="/tmp/${OUTPUT_DIR}"
mkdir -p "${LOCAL_OUTPUT_DIR}"
# Step 6: setup fortio and prometheus
function setup_fortio_and_prometheus() {
# shellcheck disable=SC2155
INGRESS_IP="$(kubectl get services -n "${NAMESPACE}" fortioclient -o jsonpath="{.status.loadBalancer.ingress[0].ip}")"
local report_port="8080"
if [[ "${LOAD_GEN_TYPE}" == "nighthawk" ]]; then
report_port="9076"
fi
export FORTIO_CLIENT_URL=http://${INGRESS_IP}:${report_port}
if [[ -z "$INGRESS_IP" ]];then
kubectl -n "${NAMESPACE}" port-forward svc/fortioclient ${report_port}:${report_port} &
CLEANUP_PIDS+=("$!")
export FORTIO_CLIENT_URL=http://localhost:${report_port}
fi
export PROMETHEUS_URL=http://localhost:9090
kubectl -n "${PROMETHEUS_NAMESPACE}" port-forward svc/istio-prometheus 9090:9090 &>/dev/null &
CLEANUP_PIDS+=("$!")
FORTIO_CLIENT_POD=$(kubectl get pods -n "${NAMESPACE}" | grep fortioclient | awk '{print $1}')
export FORTIO_CLIENT_POD
FORTIO_SERVER_POD=$(kubectl get pods -n "${NAMESPACE}" | grep fortioserver | awk '{print $1}')
export FORTIO_SERVER_POD
}
setup_fortio_and_prometheus
# Step 7: setup exit handling
function exit_handling() {
for pid in "${CLEANUP_PIDS[@]}"; do
kill "${pid}" || true
done
if [[ "${TRIALRUN}" == "True" ]]; then
exit 0
fi
# Copy raw data from fortio client pod
kubectl --namespace "${NAMESPACE}" cp "${FORTIO_CLIENT_POD}":/var/lib/fortio /tmp/rawdata -c shell
gsutil -q cp -r /tmp/rawdata "gs://${GCS_BUCKET}/${OUTPUT_DIR}/rawdata"
if [[ "${CREATE_CLUSTER}" == "true" ]]; then
# Delete cluster
pushd "${ROOT}/istio-install"
./cluster.sh delete
popd
else
# Cleanup cluster resources
cleanup
fi
}
# add trap to copy raw data when exiting, also output logging information for debugging
trap exit_handling ERR
trap exit_handling EXIT
# Step 8: run Istio performance test
# Helper functions
function collect_flame_graph() {
FLAME_OUTPUT_DIR="${WD}/flame/flameoutput"
gsutil -q cp -r "${FLAME_OUTPUT_DIR}/*.svg" "gs://${GCS_BUCKET}/${OUTPUT_DIR}/flamegraphs" || true
}
function collect_metrics() {
# shellcheck disable=SC2155
export CSV_OUTPUT="$(mktemp /tmp/benchmark_XXXX)"
pipenv run python3 fortio.py "${FORTIO_CLIENT_URL}" --csv_output="$CSV_OUTPUT" --prometheus=${PROMETHEUS_URL} \
--csv StartTime,ActualDuration,Labels,NumThreads,ActualQPS,p50,p90,p99,p999,cpu_mili_avg_istio_proxy_fortioclient,\
cpu_mili_avg_istio_proxy_fortioserver,cpu_mili_avg_istio_proxy_istio-ingressgateway,mem_Mi_avg_istio_proxy_fortioclient,\
mem_Mi_avg_istio_proxy_fortioserver,mem_Mi_avg_istio_proxy_istio-ingressgateway
gsutil -q cp "${CSV_OUTPUT}" "gs://${GCS_BUCKET}/${OUTPUT_DIR}/benchmark.csv"
}
function run_benchmark_test() {
pushd "${WD}/runner"
CONFIG_FILE="${1}"
pipenv run python3 runner.py --config_file "${CONFIG_FILE}"
if [[ "${TRIALRUN}" == "False" ]]; then
collect_metrics
fi
popd
}
function read_perf_test_conf() {
perf_test_conf="${1}"
while IFS="=" read -r key value; do
case "$key" in
'#'*) ;;
*)
# shellcheck disable=SC2086
export ${key}="${value}"
esac
done < "${perf_test_conf}"
}
function collect_envoy_info() {
CONFIG_NAME=${1}
POD_NAME=${2}
FILE_SUFFIX=${3}
ENVOY_DUMP_NAME="${LOAD_GEN_TYPE}_${POD_NAME}_${CONFIG_NAME}_${FILE_SUFFIX}.yaml"
kubectl exec -n "${NAMESPACE}" "${POD_NAME}" -c istio-proxy -- curl http://localhost:15000/"${FILE_SUFFIX}" > "${ENVOY_DUMP_NAME}"
gsutil -q cp -r "${ENVOY_DUMP_NAME}" "gs://${GCS_BUCKET}/${OUTPUT_DIR}/${FILE_SUFFIX}/${ENVOY_DUMP_NAME}"
}
function collect_config_dump() {
collect_envoy_info "${1}" "${FORTIO_CLIENT_POD}" "config_dump"
collect_envoy_info "${1}" "${FORTIO_SERVER_POD}" "config_dump"
}
function collect_clusters_info() {
collect_envoy_info "${1}" "${FORTIO_CLIENT_POD}" "clusters"
collect_envoy_info "${1}" "${FORTIO_SERVER_POD}" "clusters"
}
function collect_pod_spec() {
POD_NAME=${1}
POD_SPEC_NAME="${LOAD_GEN_TYPE}_${POD_NAME}.yaml"
kubectl get pods "${POD_NAME}" -n "${NAMESPACE}" -o yaml > "${POD_SPEC_NAME}"
gsutil -q cp -r "${POD_SPEC_NAME}" "gs://${GCS_BUCKET}/${OUTPUT_DIR}/pod_spec/${POD_SPEC_NAME}"
}
# install tools for profiling
apt-get update && apt-get -y install linux-tools-generic
# Start run perf test
echo "Start to run perf benchmark test, all collected data will be dumped to GCS bucket: ${GCS_BUCKET}/${OUTPUT_DIR}"
# Read through perf test configuration file to determine which group of test configuration to run or not run
read_perf_test_conf "${PERF_TEST_CONFIGURATION}"
for dir in "${CONFIG_DIR}"/*; do
# Get the last directory name after splitting dir path by '/', which is the configuration dir name
config_name="$(basename "${dir}")"
# skip the test config which is disabled for running
if ! ${!config_name:-false}; then
continue
fi
pushd "${dir}"
# Install istio with custom overlay
if [[ -e "./installation.yaml" ]]; then
extra_overlay="-f ${dir}/installation.yaml"
fi
pushd "${ROOT}/istio-install"
if [[ ${ISTIO_RELEASE_VERSION} ]]; then
VERSION=${INSTALL_VERSION} ./setup_istio.sh "${extra_overlay}"
else
DEV_VERSION=${INSTALL_VERSION} ./setup_istio.sh "${extra_overlay}"
fi
popd
# Custom pre-run
if [[ -e "./prerun.sh" ]]; then
# shellcheck disable=SC1091
source prerun.sh
fi
# TRIALRUN as a pre-submit check, only run agaist the first set of enabled perf run in the perf_conf file
if [[ "${TRIALRUN}" == "True" ]]; then
run_benchmark_test "${WD}/configs/trialrun.yaml"
break
fi
# Collect config_dump after prerun.sh and before test run, in order to verify test setup is correct
collect_config_dump "${config_name}"
# Collect pod spec
collect_pod_spec "${FORTIO_CLIENT_POD}"
collect_pod_spec "${FORTIO_SERVER_POD}"
# Run test and collect data
if [[ -e "./cpu_mem.yaml" ]]; then
run_benchmark_test "${dir}/cpu_mem.yaml"
fi
if [[ -e "./latency.yaml" ]]; then
run_benchmark_test "${dir}/latency.yaml"
fi
# Collect clusters info after test run and before cleanup postrun.sh run
collect_clusters_info "${config_name}"
# Custom post run
if [[ -e "./postrun.sh" ]]; then
# shellcheck disable=SC1091
source postrun.sh
fi
collect_flame_graph
# TODO: can be added to shared_postrun.sh
# restart proxy after each group
kubectl exec -n "${NAMESPACE}" "${FORTIO_CLIENT_POD}" -c istio-proxy -- curl http://localhost:15000/quitquitquit -X POST
kubectl exec -n "${NAMESPACE}" "${FORTIO_SERVER_POD}" -c istio-proxy -- curl http://localhost:15000/quitquitquit -X POST
popd
done
echo "Istio performance benchmark test is done!"