blob: 2300a013556dbaf4b0b5b697fec0ee316af237a4 [file] [log] [blame]
Milosz Wasilewski06f6c6d2016-11-09 13:16:41 +00001#!/bin/sh
2
3
4. ../../lib/sh-test-lib
5OUTPUT="$(pwd)/output"
6RESULT_FILE="${OUTPUT}/result.txt"
7LOGFILE="${OUTPUT}/ablog.txt"
8
9usage() {
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
14NUMBER=1000
15CONCURENT=100
16
17while 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
24done
25
26! check_root && error_msg "This script must be run as root"
Daniel Díaz6f49a1b2017-02-15 18:56:15 -060027create_out_dir "${OUTPUT}"
Milosz Wasilewski06f6c6d2016-11-09 13:16:41 +000028
29dist_name
30# Install and configure LEMP.
31# systemctl available on Debian 8, CentOS 7 and newer releases.
32# shellcheck disable=SC2154
33case "${dist}" in
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010034 debian)
Milosz Wasilewski06f6c6d2016-11-09 13:16:41 +000035 # Stop apache server in case it is installed and running.
36 systemctl stop apache2 > /dev/null 2>&1 || true
37
Chase Qi091c1f32017-06-23 16:05:56 +080038 pkgs="nginx apache2-utils"
39 install_deps "${pkgs}" "${SKIP_INSTALL}"
40
Milosz Wasilewski06f6c6d2016-11-09 13:16:41 +000041 systemctl restart nginx
42 ;;
Nicolas Dechesneb7e38762017-01-25 12:07:08 +010043 centos)
Milosz Wasilewski06f6c6d2016-11-09 13:16:41 +000044 # x86_64 nginx package can be installed from epel repo. However, epel
45 # project doesn't support ARM arch yet. RPB repo should provide nginx.
46 [ "$(uname -m)" = "x86_64" ] && install_deps "epel-release" "${SKIP_INSTALL}"
47 pkgs="nginx httpd-tools"
48 install_deps "${pkgs}" "${SKIP_INSTALL}"
49
50 # Stop apache server in case it is installed and running.
51 systemctl stop httpd.service > /dev/null 2>&1 || true
52
53 systemctl restart nginx
54 ;;
55 *)
56 info_msg "Supported distributions: Debian, CentOS"
57 error_msg "Unsupported distribution: ${dist}"
58 ;;
59esac
60
61# Test Apachebench on NGiNX.
62# Default index page should be OK to run ab test
63ab -n "${NUMBER}" -c "${CONCURENT}" "http://localhost/index.html" | tee "${LOGFILE}"
64# shellcheck disable=SC2129
65grep "Time taken for tests:" "${LOGFILE}" | awk '{print "Time-taken-for-tests pass " $5 " s"}' >> "${RESULT_FILE}"
66# shellcheck disable=SC2129
67grep "Complete requests:" "${LOGFILE}" | awk '{print "Complete-requests pass " $3 " items"}' >> "${RESULT_FILE}"
68# shellcheck disable=SC2129
69grep "Failed requests:" "${LOGFILE}" | awk '{ORS=""} {print "Failed-requests "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
70# shellcheck disable=SC2129
71grep "Write errors:" "${LOGFILE}" | awk '{ORS=""} {print "Write-errors "; if ($3==0) {print "pass "} else {print "fail "}; print $3 " items\n" }' >> "${RESULT_FILE}"
72# shellcheck disable=SC2129
73grep "Total transferred:" "${LOGFILE}" | awk '{print "Total-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
74# shellcheck disable=SC2129
75grep "HTML transferred:" "${LOGFILE}" | awk '{print "HTML-transferred pass " $3 " bytes"}' >> "${RESULT_FILE}"
76# shellcheck disable=SC2129
77grep "Requests per second:" "${LOGFILE}" | awk '{print "Requests-per-second pass " $4 " #/s"}' >> "${RESULT_FILE}"
78# shellcheck disable=SC2129
79grep "Time per request:" "${LOGFILE}" | grep -v "across" | awk '{print "Time-per-request-mean pass " $4 " ms"}' >> "${RESULT_FILE}"
80# shellcheck disable=SC2129
81grep "Time per request:" "${LOGFILE}" | grep "across" | awk '{print "Time-per-request-concurent pass " $4 " ms"}' >> "${RESULT_FILE}"
82# shellcheck disable=SC2129
83grep "Transfer rate:" "${LOGFILE}" | awk '{print "Transfer-rate pass " $3 " kb/s"}' >> "${RESULT_FILE}"