-
Notifications
You must be signed in to change notification settings - Fork 1
/
curl-basher.sh
executable file
·58 lines (51 loc) · 1.17 KB
/
curl-basher.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
#!/bin/bash
usage() {
echo "Usage: $1 <concurrency> <iterations> <url>"
echo ""
echo "Example: $1 4 100 http://127.0.0.1:8080"
echo ""
echo " Will run 4 concurrent curl requests"
echo " 100 times against 127.0.0.1:8080"
echo ""
exit 1
}
[ $# -gt 2 ] || usage $0
TMP=/tmp/loadtest.$$.tmp
CONCURRENCY=$1
ITERATIONS=$2
URL=$3
runtest() {
CONCURRENCY=$1
ITERATIONS=$2
URL=$3
declare -a PIDS=()
for (( j = 1; j <= $CONCURRENCY; j++ ))
do
(
for (( i = 1; i <= $ITERATIONS; i++ ))
do
curl -o /dev/null $URL 2>/dev/null ;
if [ $? != 0 ]; then
echo "ERROR"
fi
if [ $j == 1 ]; then
echo -n "."
fi
done
) &
PIDS[${j}]=$!
done
for PID in ${PIDS[*]}; do
wait $PID
done
echo ""
}
time ( runtest $CONCURRENCY $ITERATIONS $URL ) 2>$TMP
REQS=`expr $ITERATIONS \* $CONCURRENCY`
TIMESTR=`awk '$1=="real"{print $2}' $TMP`
MINS=`echo "$TIMESTR" |cut -dm -f1`
SECS=`echo "$TIMESTR" |cut -dm -f2 |cut -ds -f1`
TOTSECS=`echo "(${MINS} * 60)+${SECS}" |bc`
RPS=`echo "$REQS / $TOTSECS" |bc`
echo "$REQS requests completed in $TIMESTR = $RPS requests/second"
rm $TMP