Skip to content

Commit 6047f6c

Browse files
committed
Grab errors & update the code
1 parent c33676f commit 6047f6c

File tree

1 file changed

+52
-25
lines changed

1 file changed

+52
-25
lines changed

base/_functions.sh

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
benchmark () {
22
fw="$1"
33
url="$2"
4-
output_wrk="output/$dir_datetime/$fw.wrk.log"
4+
output_wrk_address="output/$dir_datetime/$fw.wrk.log"
55
output="output/$dir_datetime/$fw.output"
66

77
# check out the appropriate response is reachable
@@ -10,6 +10,28 @@ benchmark () {
1010
# find 'done'
1111
status=${url_status%%${fw}*}
1212

13+
count=5
14+
total=0
15+
i=0
16+
# The for (( expr ; expr ; expr )) syntax is not available in sh, so:
17+
while [ $i -lt $count ]
18+
do
19+
curl -sS "$url" > "$output"
20+
t=`tail -1 "$output" | cut -f 2 -d ':'`
21+
total=`php ./libs/sum_ms.php $t $total`
22+
i=$(( $i + 1 ))
23+
done
24+
time=`php ./libs/avg_ms.php $total $count`
25+
26+
27+
# get memory and file
28+
memory=`tail -1 "$output" | cut -f 1 -d ':'`
29+
file=`tail -1 "$output" | cut -f 3 -d ':'`
30+
31+
32+
# to make a small gap between the WRK and CURL
33+
sleep 1
34+
1335
# if the index of 'done' be equal to
1436
# the length of the url_status then
1537
# the appropriate output (Hello World! ...) not reachable
@@ -36,47 +58,52 @@ benchmark () {
3658

3759
echo $config_wrk
3860

39-
config_wrk="$config_wrk '$url' > '$output_wrk'"
61+
config_wrk="$config_wrk '$url' > '$output_wrk_address'"
4062
eval $config_wrk
4163

42-
rps=`grep "Requests/sec:" "$output_wrk" | tr -cd '0-9.'`
64+
output_wrk=$(cat "$output_wrk_address")
4365

66+
rps=$( echo "$output_wrk" | grep "Requests/sec:" | sed -n 's/.* \([.0-9]*\).*/\1/p')
4467
echo "rps: $rps"
4568

46-
# to make a small gap between the WRK and CURL
47-
sleep 1
69+
socket_errors=$(echo "$output_wrk" | grep "Socket errors" | sed -n 's/.*: \(.*\).*/\1/p')
70+
connect_errors=0
71+
read_errors=0
72+
write_errors=0
73+
timeout_errors=0
74+
total_socket_errors=0
75+
76+
if [ -n "${socket_errors}" ]; then
77+
connect_errors=$(echo "$socket_errors" | sed -n 's/.*connect \([0-9]*\).*/\1/p')
78+
read_errors=$(echo "$socket_errors" | sed -n 's/.*read \([0-9]*\).*/\1/p')
79+
write_errors=$(echo "$socket_errors" | sed -n 's/.*write \([0-9]*\).*/\1/p')
80+
timeout_errors=$(echo "$socket_errors" | sed -n 's/.*timeout \([0-9]*\).*/\1/p')
81+
total_socket_errors=$(( connect_errors + read_errors + write_errors + timeout_errors ))
82+
else
83+
socket_errors=0
84+
fi
4885

49-
count=5
50-
total=0
51-
i=0
52-
# The for (( expr ; expr ; expr )) syntax is not available in sh, so:
53-
while [ $i -lt $count ]
54-
do
55-
curl -sS "$url" > "$output"
56-
t=`tail -1 "$output" | cut -f 2 -d ':'`
57-
total=`php ./libs/sum_ms.php $t $total`
58-
i=$(( $i + 1 ))
59-
done
60-
time=`php ./libs/avg_ms.php $total $count`
86+
non_2xx_3xx=$(echo "$output_wrk" | grep "Non-2xx or 3xx responses:" | sed -n 's/.* \([0-9]*\).*/\1/p')
87+
if [ -z "${non_2xx_3xx}" ]; then
88+
non_2xx_3xx=0
89+
fi
6190

6291

63-
# get memory and file
64-
memory=`tail -1 "$output" | cut -f 1 -d ':'`
65-
file=`tail -1 "$output" | cut -f 3 -d ':'`
92+
echo "socket_errors: $socket_errors, total $total_socket_errors, non 2xx/3xx $non_2xx_3xx"
6693

67-
echo "$fw: $rps: $memory: $time: $file" >> "$results_file"
94+
echo "$fw: $rps: $memory: $time: $file: $duration: $connect_errors: $read_errors: $write_errors: $timeout_errors: $non_2xx_3xx" >> "$results_file"
6895

6996
echo "$fw" >> "$check_file"
70-
grep "Document Length:" "$output_wrk" >> "$check_file"
71-
grep "Failed requests:" "$output_wrk" >> "$check_file"
97+
grep "Document Length:" "$output_wrk_address" >> "$check_file"
98+
grep "Failed requests:" "$output_wrk_address" >> "$check_file"
7299
grep 'Hello World!' "$output" >> "$check_file"
73100

74101
# check errors
75102
touch "$error_file"
76103
error=''
77-
x=`grep 'Failed requests: 0' "$output_wrk"`
104+
x=`grep 'Failed requests: 0' "$output_wrk_address"`
78105
if [ "$x" = "" ]; then
79-
tmp=`grep "Failed requests:" "$output_wrk"`
106+
tmp=`grep "Failed requests:" "$output_wrk_address"`
80107
error="$error$tmp"
81108
fi
82109
x=`grep 'Hello World!' "$output"`

0 commit comments

Comments
 (0)