-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstress-test.sh
executable file
·79 lines (61 loc) · 1.18 KB
/
stress-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
#### Default Configuration
CONCURRENCY=4
REQUESTS=100
ADDRESS="https://count.webconverger.com/"
show_help() {
cat << EOF
Naive Stress Test with cURL.
Usage: ./stress-test.sh [-a ADDRESS] [-c CONCURRENCY] [-r REQUESTS]
Params:
-a address to be tested.
Defaults to localhost:8080
-c conccurency: how many process to spawn
Defaults to 1
-r number of requests per process
Defaults to 10
-h show this help text
Example:
$ ./stress-test.sh -c 4 -p 100 (400 requests to localhost:8080)
EOF
}
#### CLI
while getopts ":a:c:r:h" opt; do
case $opt in
a)
ADDRESS=$OPTARG
;;
c)
CONCURRENCY=$OPTARG
;;
r)
REQUESTS=$OPTARG
;;
h)
show_help
exit 0
;;
\?)
show_help >&2
echo "Invalid argument: $OPTARG" &2
exit 1
;;
esac
done
shift $((OPTIND-1))
#### Main
for i in `seq 1 $CONCURRENCY`; do
curl -s "$ADDRESS?[1-$REQUESTS]" & pidlist="$pidlist $!"
done
# Execute and wait
FAIL=0
for job in $pidlist; do
echo $job
wait $job || let "FAIL += 1"
done
# Verify if any failed
if [ "$FAIL" -eq 0 ]; then
echo "SUCCESS!"
else
echo "Failed Requests: ($FAIL)"
fi