Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | _ARG_CFG="${1}" |
Miroslav Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 4 | _ARG_DIR="${2:-${1}}" |
Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 5 | _LOG_DIR="_logs" |
| 6 | _HTTPD_PIDFILE="${_LOG_DIR}/thttpd.pid" |
Miroslav Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 7 | _USAGE_MSG="usage: $(basename "${0}") cfg [dir]" |
Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 8 | |
| 9 | |
Miroslav Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 10 | sh_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 Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 26 | httpd_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 | |
| 34 | httpd_stop () |
| 35 | { |
| 36 | test -e "${_HTTPD_PIDFILE}" || return |
| 37 | |
| 38 | kill -TERM "$(cat ${_HTTPD_PIDFILE})" |
| 39 | rm "${_HTTPD_PIDFILE}" |
| 40 | } |
| 41 | |
| 42 | haproxy_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 | |
| 70 | wrk_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 Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 83 | command -v thttpd >/dev/null 2>&1 || sh_exit "thttpd: command not found" 5 |
| 84 | command -v wrk >/dev/null 2>&1 || sh_exit "wrk: command not found" 6 |
| 85 | |
| 86 | mkdir -p "${_LOG_DIR}" || sh_exit "${_LOG_DIR}: Cannot create log directory" 1 |
Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 87 | |
| 88 | if test "${_ARG_CFG}" = "all"; then |
Miroslav Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 89 | "${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 Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 93 | exit 0 |
| 94 | fi |
| 95 | |
Miroslav Zagorac | 1bd0222 | 2022-03-09 17:34:11 +0100 | [diff] [blame^] | 96 | test -z "${_ARG_CFG}" -o -z "${_ARG_DIR}" && sh_exit "${_USAGE_MSG}" 4 |
| 97 | test -f "run-${_ARG_CFG}.sh" || sh_exit "run-${_ARG_CFG}.sh: No such configuration script" 2 |
| 98 | test -d "${_ARG_DIR}" || sh_exit "${_ARG_DIR}: No such directory" 3 |
Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 99 | |
| 100 | test -e "${_ARG_DIR}/haproxy.cfg.in" || cp -af "${_ARG_DIR}/haproxy.cfg" "${_ARG_DIR}/haproxy.cfg.in" |
| 101 | test -e "${_ARG_DIR}/ot.cfg.in" || cp -af "${_ARG_DIR}/ot.cfg" "${_ARG_DIR}/ot.cfg.in" |
| 102 | if 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" |
| 105 | fi |
| 106 | |
| 107 | httpd_run |
| 108 | |
| 109 | for _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 |
| 115 | done |
| 116 | |
| 117 | httpd_stop |