Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | _ARG_CFG="${1}" |
| 4 | _ARG_DIR="${2}" |
| 5 | _LOG_DIR="_logs" |
| 6 | _HTTPD_PIDFILE="${_LOG_DIR}/thttpd.pid" |
| 7 | |
| 8 | |
| 9 | httpd_run () |
| 10 | { |
| 11 | |
| 12 | test -e "${_HTTPD_PIDFILE}" && return |
| 13 | |
| 14 | thttpd -p 8000 -d . -nos -nov -l /dev/null -i "${_HTTPD_PIDFILE}" |
| 15 | } |
| 16 | |
| 17 | httpd_stop () |
| 18 | { |
| 19 | test -e "${_HTTPD_PIDFILE}" || return |
| 20 | |
| 21 | kill -TERM "$(cat ${_HTTPD_PIDFILE})" |
| 22 | rm "${_HTTPD_PIDFILE}" |
| 23 | } |
| 24 | |
| 25 | haproxy_run () |
| 26 | { |
| 27 | _arg_ratio="${1}" |
| 28 | _var_sed_ot= |
| 29 | _var_sed_haproxy= |
| 30 | |
| 31 | if test "${_arg_ratio}" = "disabled"; then |
| 32 | _var_sed_ot="s/no \(option disabled\)/\1/" |
| 33 | elif test "${_arg_ratio}" = "off"; then |
| 34 | _var_sed_haproxy="s/^\(.* filter opentracing .*\)/#\1/g; s/^\(.* ot-group .*\)/#\1/g" |
| 35 | else |
| 36 | _var_sed_ot="s/\(rate-limit\) 100.0/\1 ${_arg_ratio}/" |
| 37 | fi |
| 38 | |
| 39 | sed "${_var_sed_haproxy}" "${_ARG_DIR}/haproxy.cfg.in" > "${_ARG_DIR}/haproxy.cfg" |
| 40 | sed "${_var_sed_ot}" "${_ARG_DIR}/ot.cfg.in" > "${_ARG_DIR}/ot.cfg" |
| 41 | |
| 42 | if test "${_ARG_DIR}" = "fe"; then |
| 43 | if test "${_arg_ratio}" = "disabled" -o "${_arg_ratio}" = "off"; then |
| 44 | sed "${_var_sed_haproxy}" "be/haproxy.cfg.in" > "be/haproxy.cfg" |
| 45 | sed "${_var_sed_ot}" "be/ot.cfg.in" > "be/ot.cfg" |
| 46 | fi |
| 47 | fi |
| 48 | |
| 49 | ./run-${_ARG_CFG}.sh & |
| 50 | sleep 5 |
| 51 | } |
| 52 | |
| 53 | wrk_run () |
| 54 | { |
| 55 | _arg_ratio="${1}" |
| 56 | |
| 57 | echo "--- rate-limit ${_arg_ratio} --------------------------------------------------" |
| 58 | wrk -c8 -d300 -t8 --latency http://localhost:10080/index.html |
| 59 | echo "----------------------------------------------------------------------" |
| 60 | echo |
| 61 | |
| 62 | sleep 10 |
| 63 | } |
| 64 | |
| 65 | |
| 66 | mkdir -p "${_LOG_DIR}" || exit 1 |
| 67 | |
| 68 | if test "${_ARG_CFG}" = "all"; then |
| 69 | ${0} fe-be fe > "${_LOG_DIR}/README-speed-fe-be" |
| 70 | ${0} sa sa > "${_LOG_DIR}/README-speed-sa" |
| 71 | ${0} cmp cmp > "${_LOG_DIR}/README-speed-cmp" |
| 72 | ${0} ctx ctx > "${_LOG_DIR}/README-speed-ctx" |
| 73 | exit 0 |
| 74 | fi |
| 75 | |
| 76 | test -n "${_ARG_CFG}" -a -f "run-${_ARG_CFG}.sh" || exit 2 |
| 77 | test -n "${_ARG_DIR}" -a -d "${_ARG_DIR}" || exit 3 |
| 78 | |
| 79 | test -e "${_ARG_DIR}/haproxy.cfg.in" || cp -af "${_ARG_DIR}/haproxy.cfg" "${_ARG_DIR}/haproxy.cfg.in" |
| 80 | test -e "${_ARG_DIR}/ot.cfg.in" || cp -af "${_ARG_DIR}/ot.cfg" "${_ARG_DIR}/ot.cfg.in" |
| 81 | if test "${_ARG_DIR}" = "fe"; then |
| 82 | test -e "be/haproxy.cfg.in" || cp -af "be/haproxy.cfg" "be/haproxy.cfg.in" |
| 83 | test -e "be/ot.cfg.in" || cp -af "be/ot.cfg" "be/ot.cfg.in" |
| 84 | fi |
| 85 | |
| 86 | httpd_run |
| 87 | |
| 88 | for _var_ratio in 100.0 50.0 10.0 2.5 0.0 disabled off; do |
| 89 | haproxy_run "${_var_ratio}" |
| 90 | wrk_run "${_var_ratio}" |
| 91 | |
| 92 | pkill --signal SIGUSR1 haproxy |
| 93 | wait |
| 94 | done |
| 95 | |
| 96 | httpd_stop |