forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webtooling.sh
executable file
·283 lines (240 loc) · 8.32 KB
/
webtooling.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
#!/bin/bash
#
# Copyright (c) 2020-2023 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
# Description of the test:
# This test runs the 'web tooling benchmark'
# https://github.com/v8/web-tooling-benchmark
set -o pipefail
# General env
SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
source "${SCRIPT_PATH}/../lib/common.bash"
NUM_CONTAINERS="${1:-}"
IMAGE="docker.io/library/local-web-tooling:latest"
DOCKERFILE="${SCRIPT_PATH}/web-tooling-dockerfile/Dockerfile"
# Directory to run the test inside of the container
TESTDIR="${TESTDIR:-/testdir}"
file_path="/web-tooling-benchmark"
file_name="output"
# Directory where the webtooling results are stored
TMP_DIR=$(mktemp --tmpdir -d webtool.XXXXXXXXXX)
# Options to control the start of the workload using a trigger-file
dst_dir="/host"
src_dir=$(mktemp --tmpdir -d webtool.XXXXXXXXXX)
trigger_file="$RANDOM.txt"
guest_trigger_file="$dst_dir/$trigger_file"
host_trigger_file="$src_dir/$trigger_file"
start_script="webtooling_start.sh"
# CMD points to the script that starts the workload
CMD="$dst_dir/$start_script"
MOUNT_OPTIONS="type=bind,src=$src_dir,dst=$dst_dir,options=rbind:ro"
PAYLOAD_ARGS="${PAYLOAD_ARGS:-tail -f /dev/null}"
# This timeout is related with the amount of time that
# webtool benchmark needs to run inside the container
timeout=600
INITIAL_NUM_PIDS=1
cpu_period="100000"
cpu_quota="200000"
function remove_tmp_dir() {
rm -rf "$TMP_DIR"
rm -rf "$src_dir"
}
trap remove_tmp_dir EXIT
# Show help about this script
function help(){
cat << EOF
Usage: $0 <count>
Description:
<count> : Number of containers to run.
EOF
}
# script used to launch the workload
function create_start_script() {
local script="${src_dir/$start_script}"
rm -rf "${script}"
cat <<EOF >>"${script}"
#!/bin/bash
mkdir -p "${TESTDIR}"
until [ -f ${guest_trigger_file} ]; do
sleep 1
done
pushd "${file_path}"
node dist/cli.js > "${file_name}"
EOF
chmod +x "${script}"
}
function verify_task_is_completed_on_all_containers() {
local containers=( $(sudo -E "${CTR_EXE}" c list -q) )
local sleep_secs=10
local max=$(bc <<<"${timeout} / ${sleep_secs}")
local wip_list=()
local count=1
local sum=0
local i=""
while (( ${sum} < ${NUM_CONTAINERS} )); do
for i in "${containers[@]}"; do
# Only check containers that have not completed the workload at this step
num_pids=$(sudo -E "${CTR_EXE}" t metrics "${i}" | grep pids.current | grep pids.current | xargs | cut -d ' ' -f 2)
if [ "${num_pids}" -lt "${INITIAL_NUM_PIDS}" ]; then
((sum++))
else
wip_list+=("${i}")
fi
done
# hold the list of containers that are still running the workload
containers=(${wip_list[*]})
wip_list=()
info "loop ${count} of ${max}: sleeping for ${sleep_secs} seconds"
sleep "${sleep_secs}"
((count++))
done
}
function check_containers_are_up() {
info "Verify that the containers are running"
local containers_launched=0
while (( $containers_launched < ${NUM_CONTAINERS} )); do
containers_launched="$(sudo -E ${CTR_EXE} t list | grep -c "RUNNING")"
sleep 1
done
}
function save_config() {
metrics_json_start_array
local json="$(cat << EOF
{
"containers": "${NUM_CONTAINERS}",
"image": "${IMAGE}",
"units": "runs/s"
}
EOF
)"
metrics_json_add_array_element "${json}"
metrics_json_end_array "Config"
}
function main() {
# Verify enough arguments
if [ $# != 1 ]; then
echo >&2 "error: Not enough arguments [$@]"
help
exit 1
fi
local i=0
local containers=()
local cmds=("docker")
local not_started_count=$NUM_CONTAINERS
restart_containerd_service
# Check tools/commands dependencies
init_env
check_cmds "${cmds[@]}"
check_ctr_images "$IMAGE" "$DOCKERFILE"
metrics_json_init
save_config
create_start_script
rm -rf "${host_trigger_file}"
info "Creating ${NUM_CONTAINERS} containers"
for ((i=1; i<= "${NUM_CONTAINERS}"; i++)); do
containers+=($(random_name))
# Web tool benchmark needs 2 cpus to run completely in its cpu utilization
sudo -E "${CTR_EXE}" run -d --runtime "${CTR_RUNTIME}" --cpu-quota "${cpu_quota}" --cpu-period "${cpu_period}" --mount="${MOUNT_OPTIONS}" "${IMAGE}" "${containers[-1]}" sh -c "${PAYLOAD_ARGS}"
((not_started_count--))
info "${not_started_count} remaining containers"
done
# Check that the requested number of containers are running
local timeout_launch="10"
check_containers_are_up & pid=$!
(sleep "${timeout_launch}" && kill -HUP ${pid}) 2>/dev/null & pid_tout=$!
if wait $pid 2>/dev/null; then
pkill -HUP -P "${pid_tout}"
wait "${pid_tout}"
else
warn "Time out exceeded"
return 1
fi
# Get the initial number of pids in a single container before the workload starts
INITIAL_NUM_PIDS=$(sudo -E "${CTR_EXE}" t metrics "${containers[-1]}" | grep pids.current | grep pids.current | xargs | cut -d ' ' -f 2)
((INITIAL_NUM_PIDS++))
# Launch webtooling benchmark
local pids=()
local j=0
for i in "${containers[@]}"; do
$(sudo -E "${CTR_EXE}" t exec -d --exec-id "$(random_name)" "${i}" sh -c "${CMD}") &
pids[${j}]=$!
((j++))
done
# wait for all pids
for pid in ${pids[*]}; do
wait "${pid}"
done
touch "${host_trigger_file}"
info "All containers are running the workload..."
# Verify that all containers have completed the assigned task
verify_task_is_completed_on_all_containers & pid=$!
(sleep "$timeout" && kill -HUP $pid) 2>/dev/null & pid_tout=$!
if wait ${pid} 2>/dev/null; then
pkill -HUP -P "${pid_tout}"
wait "${pid_tout}"
else
warn "Time out exceeded"
return 1
fi
RESULTS_CMD="cat ${file_path}/${file_name}"
for i in "${containers[@]}"; do
sudo -E "${CTR_EXE}" t exec --exec-id "${RANDOM}" "${i}" sh -c "${RESULTS_CMD}" >> "${TMP_DIR}/results"
done
# Save configuration
metrics_json_start_array
local output=$(cat "${TMP_DIR}/results")
local cut_results="cut -d':' -f2 | sed -e 's/^[ \t]*//'| cut -d ' ' -f1 | tr '\n' ',' | sed 's/.$//'"
local acorn=$(echo "${output}" | grep -w "acorn" | eval "${cut_results}")
local babel=$(echo "${output}" | grep -w "babel" | sed '/babel-minify/d' | eval "${cut_results}")
local babel_minify=$(echo "${output}" | grep -w "babel-minify" | eval "${cut_results}")
local babylon=$(echo "${output}" | grep -w "babylon" | eval "${cut_results}")
local buble=$(echo "${output}" | grep -w "buble" | eval "${cut_results}")
local chai=$(echo "${output}" | grep -w "chai" | eval "${cut_results}")
local coffeescript=$(echo "${output}" | grep -w "coffeescript" | eval "${cut_results}")
local espree=$(echo "${output}" | grep -w "espree" | eval "${cut_results}")
local esprima=$(echo "${output}" | grep -w "esprima" | eval "${cut_results}")
local jshint=$(echo "${output}" | grep -w "jshint" | eval "${cut_results}")
local lebab=$(echo "${output}" | grep -w "lebab" | eval "${cut_results}")
local postcss=$(echo "${output}" | grep -w "postcss" | eval "${cut_results}")
local prepack=$(echo "${output}" | grep -w "prepack" | eval "${cut_results}")
local prettier=$(echo "${output}" | grep -w "prettier" | eval "${cut_results}")
local source_map=$(echo "${output}" | grep -w "source-map" | eval "${cut_results}")
local terser=$(echo "${output}" | grep -w "terser" | eval "${cut_results}")
local typescript=$(echo "${output}" | grep -w "typescript" | eval "${cut_results}")
local uglify_js=$(echo "${output}" | grep -w "uglify-js" | eval "${cut_results}")
local geometric_mean=$(echo "${output}" | grep -w "Geometric" | eval "${cut_results}")
local average_tps=$(echo "${geometric_mean}" | sed "s/,/+/g;s/.*/(&)\/$NUM_CONTAINERS/g" | bc -l)
local tps=$(echo "${average_tps}*${NUM_CONTAINERS}" | bc -l)
local json="$(cat << EOF
{
"Acorn" : "${acorn}",
"Babel" : "${babel}",
"Babel minify" : "${babel_minify}",
"Babylon" : "${babylon}",
"Buble" : "${buble}",
"Chai" : "${chai}",
"Coffeescript" : "${coffeescript}",
"Espree" : "${espree}",
"Esprima" : "${esprima}",
"Jshint" : "${jshint}",
"Lebab" : "${lebab}",
"Postcss" : "${postcss}",
"Prepack" : "${prepack}",
"Prettier" : "${prettier}",
"Source map" : "${source_map}",
"Terser" : "${terser}",
"Typescript" : "${typescript}",
"Uglify js" : "${uglify_js}",
"Geometric mean" : "${geometric_mean}",
"Average TPS" : "${average_tps}",
"TPS" : "${tps}"
}
EOF
)"
metrics_json_add_array_element "${json}"
metrics_json_end_array "Results"
metrics_json_save
clean_env_ctr
}
main "$@"