blob: f2ac5140eb994f568e800d32841f8e4f3d95f280 [file] [log] [blame]
Miroslav Zagorac70230c62020-12-09 16:54:31 +01001#!/bin/sh
2#
3 _ARG_CFG="${1}"
Miroslav Zagorac1bd02222022-03-09 17:34:11 +01004 _ARG_DIR="${2:-${1}}"
Miroslav Zagorac70230c62020-12-09 16:54:31 +01005 _LOG_DIR="_logs"
6_HTTPD_PIDFILE="${_LOG_DIR}/thttpd.pid"
Miroslav Zagorac1bd02222022-03-09 17:34:11 +01007 _USAGE_MSG="usage: $(basename "${0}") cfg [dir]"
Miroslav Zagorac70230c62020-12-09 16:54:31 +01008
9
Miroslav Zagorac1bd02222022-03-09 17:34:11 +010010sh_exit ()
11{
12 test -z "${2}" && {
13 echo
14 echo "Script killed!"
15 }
16
17 test -n "${1}" && {
18 echo
19 echo "${1}"
20 echo
21 }
22
23 exit ${2:-64}
24}
25
Miroslav Zagorac70230c62020-12-09 16:54:31 +010026httpd_run ()
27{
28
29 test -e "${_HTTPD_PIDFILE}" && return
30
31 thttpd -p 8000 -d . -nos -nov -l /dev/null -i "${_HTTPD_PIDFILE}"
32}
33
34httpd_stop ()
35{
36 test -e "${_HTTPD_PIDFILE}" || return
37
38 kill -TERM "$(cat ${_HTTPD_PIDFILE})"
39 rm "${_HTTPD_PIDFILE}"
40}
41
42haproxy_run ()
43{
44 _arg_ratio="${1}"
45 _var_sed_ot=
46 _var_sed_haproxy=
47
48 if test "${_arg_ratio}" = "disabled"; then
49 _var_sed_ot="s/no \(option disabled\)/\1/"
50 elif test "${_arg_ratio}" = "off"; then
51 _var_sed_haproxy="s/^\(.* filter opentracing .*\)/#\1/g; s/^\(.* ot-group .*\)/#\1/g"
52 else
53 _var_sed_ot="s/\(rate-limit\) 100.0/\1 ${_arg_ratio}/"
54 fi
55
56 sed "${_var_sed_haproxy}" "${_ARG_DIR}/haproxy.cfg.in" > "${_ARG_DIR}/haproxy.cfg"
57 sed "${_var_sed_ot}" "${_ARG_DIR}/ot.cfg.in" > "${_ARG_DIR}/ot.cfg"
58
59 if test "${_ARG_DIR}" = "fe"; then
60 if test "${_arg_ratio}" = "disabled" -o "${_arg_ratio}" = "off"; then
61 sed "${_var_sed_haproxy}" "be/haproxy.cfg.in" > "be/haproxy.cfg"
62 sed "${_var_sed_ot}" "be/ot.cfg.in" > "be/ot.cfg"
63 fi
64 fi
65
66 ./run-${_ARG_CFG}.sh &
67 sleep 5
68}
69
70wrk_run ()
71{
72 _arg_ratio="${1}"
73
74 echo "--- rate-limit ${_arg_ratio} --------------------------------------------------"
75 wrk -c8 -d300 -t8 --latency http://localhost:10080/index.html
76 echo "----------------------------------------------------------------------"
77 echo
78
79 sleep 10
80}
81
82
Miroslav Zagorac1bd02222022-03-09 17:34:11 +010083command -v thttpd >/dev/null 2>&1 || sh_exit "thttpd: command not found" 5
84command -v wrk >/dev/null 2>&1 || sh_exit "wrk: command not found" 6
85
86mkdir -p "${_LOG_DIR}" || sh_exit "${_LOG_DIR}: Cannot create log directory" 1
Miroslav Zagorac70230c62020-12-09 16:54:31 +010087
88if test "${_ARG_CFG}" = "all"; then
Miroslav Zagorac1bd02222022-03-09 17:34:11 +010089 "${0}" fe-be fe > "${_LOG_DIR}/README-speed-fe-be"
90 "${0}" sa sa > "${_LOG_DIR}/README-speed-sa"
91 "${0}" cmp cmp > "${_LOG_DIR}/README-speed-cmp"
92 "${0}" ctx ctx > "${_LOG_DIR}/README-speed-ctx"
Miroslav Zagorac70230c62020-12-09 16:54:31 +010093 exit 0
94fi
95
Miroslav Zagorac1bd02222022-03-09 17:34:11 +010096test -z "${_ARG_CFG}" -o -z "${_ARG_DIR}" && sh_exit "${_USAGE_MSG}" 4
97test -f "run-${_ARG_CFG}.sh" || sh_exit "run-${_ARG_CFG}.sh: No such configuration script" 2
98test -d "${_ARG_DIR}" || sh_exit "${_ARG_DIR}: No such directory" 3
Miroslav Zagorac70230c62020-12-09 16:54:31 +010099
100test -e "${_ARG_DIR}/haproxy.cfg.in" || cp -af "${_ARG_DIR}/haproxy.cfg" "${_ARG_DIR}/haproxy.cfg.in"
101test -e "${_ARG_DIR}/ot.cfg.in" || cp -af "${_ARG_DIR}/ot.cfg" "${_ARG_DIR}/ot.cfg.in"
102if test "${_ARG_DIR}" = "fe"; then
103 test -e "be/haproxy.cfg.in" || cp -af "be/haproxy.cfg" "be/haproxy.cfg.in"
104 test -e "be/ot.cfg.in" || cp -af "be/ot.cfg" "be/ot.cfg.in"
105fi
106
107httpd_run
108
109for _var_ratio in 100.0 50.0 10.0 2.5 0.0 disabled off; do
110 haproxy_run "${_var_ratio}"
111 wrk_run "${_var_ratio}"
112
113 pkill --signal SIGUSR1 haproxy
114 wait
115done
116
117httpd_stop