Milosz Wasilewski | 06f6c6d | 2016-11-09 13:16:41 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | |
| 4 | . ../../lib/sh-test-lib |
| 5 | OUTPUT="$(pwd)/output" |
| 6 | RESULT_FILE="${OUTPUT}/result.txt" |
| 7 | LOGFILE="${OUTPUT}/ablog.txt" |
| 8 | |
| 9 | usage() { |
| 10 | echo "Usage: $0 [-s <true|false>] [-n <numer_or_requests>] [-c <number_of_requests_at_a_time>] " 1>&2 |
| 11 | exit 1 |
| 12 | } |
| 13 | |
| 14 | NUMBER=1000 |
| 15 | CONCURENT=100 |
| 16 | |
| 17 | while getopts "s:n:c:" o; do |
| 18 | case "$o" in |
| 19 | n) NUMBER="${OPTARG}" ;; |
| 20 | c) CONCURENT="${OPTARG}" ;; |
| 21 | s) SKIP_INSTALL="${OPTARG}" ;; |
| 22 | *) usage ;; |
| 23 | esac |
| 24 | done |
| 25 | |
| 26 | ! check_root && error_msg "This script must be run as root" |
| 27 | [ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)" |
| 28 | mkdir -p "${OUTPUT}" |
| 29 | |
| 30 | dist_name |
| 31 | # Install and configure LEMP. |
| 32 | # systemctl available on Debian 8, CentOS 7 and newer releases. |
| 33 | # shellcheck disable=SC2154 |
| 34 | case "${dist}" in |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame^] | 35 | debian) |
Milosz Wasilewski | 06f6c6d | 2016-11-09 13:16:41 +0000 | [diff] [blame] | 36 | pkgs="nginx apache2-utils" |
| 37 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
| 38 | |
| 39 | # Stop apache server in case it is installed and running. |
| 40 | systemctl stop apache2 > /dev/null 2>&1 || true |
| 41 | |
| 42 | systemctl restart nginx |
| 43 | ;; |
Nicolas Dechesne | b7e3876 | 2017-01-25 12:07:08 +0100 | [diff] [blame^] | 44 | centos) |
Milosz Wasilewski | 06f6c6d | 2016-11-09 13:16:41 +0000 | [diff] [blame] | 45 | # x86_64 nginx package can be installed from epel repo. However, epel |
| 46 | # project doesn't support ARM arch yet. RPB repo should provide nginx. |
| 47 | [ "$(uname -m)" = "x86_64" ] && install_deps "epel-release" "${SKIP_INSTALL}" |
| 48 | pkgs="nginx httpd-tools" |
| 49 | install_deps "${pkgs}" "${SKIP_INSTALL}" |
| 50 | |
| 51 | # Stop apache server in case it is installed and running. |
| 52 | systemctl stop httpd.service > /dev/null 2>&1 || true |
| 53 | |
| 54 | systemctl restart nginx |
| 55 | ;; |
| 56 | *) |
| 57 | info_msg "Supported distributions: Debian, CentOS" |
| 58 | error_msg "Unsupported distribution: ${dist}" |
| 59 | ;; |
| 60 | esac |
| 61 | |
| 62 | # Test Apachebench on NGiNX. |
| 63 | # Default index page should be OK to run ab test |
| 64 | ab -n "${NUMBER}" -c "${CONCURENT}" "http://localhost/index.html" | tee "${LOGFILE}" |
| 65 | # shellcheck disable=SC2129 |
| 66 | grep "Time taken for tests:" "${LOGFILE}" | awk '{print "Time-taken-for-tests pass " $5 " s"}' >> "${RESULT_FILE}" |
| 67 | # shellcheck disable=SC2129 |
| 68 | grep "Complete requests:" "${LOGFILE}" | awk '{print "Complete-requests pass " $3 " items"}' >> "${RESULT_FILE}" |
| 69 | # shellcheck disable=SC2129 |
| 70 | grep "Failed requests:" "${LOGFILE}" | awk '{ORS=""} {print "Failed-requests "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}" |
| 71 | # shellcheck disable=SC2129 |
| 72 | grep "Write errors:" "${LOGFILE}" | awk '{ORS=""} {print "Write-errors "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}" |
| 73 | # shellcheck disable=SC2129 |
| 74 | grep "Total transferred:" "${LOGFILE}" | awk '{print "Total-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}" |
| 75 | # shellcheck disable=SC2129 |
| 76 | grep "HTML transferred:" "${LOGFILE}" | awk '{print "HTML-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}" |
| 77 | # shellcheck disable=SC2129 |
| 78 | grep "Requests per second:" "${LOGFILE}" | awk '{print "Requests-per-second pass " $4 " #/s"}' >> "${RESULT_FILE}" |
| 79 | # shellcheck disable=SC2129 |
| 80 | grep "Time per request:" "${LOGFILE}" | grep -v "across" | awk '{print "Time-per-request-mean pass " $4 " ms"}' >> "${RESULT_FILE}" |
| 81 | # shellcheck disable=SC2129 |
| 82 | grep "Time per request:" "${LOGFILE}" | grep "across" | awk '{print "Time-per-request-concurent pass " $4 " ms"}' >> "${RESULT_FILE}" |
| 83 | # shellcheck disable=SC2129 |
| 84 | grep "Transfer rate:" "${LOGFILE}" | awk '{print "Transfer-rate pass " $3 " kb/s"}' >> "${RESULT_FILE}" |