forked from specialunderwear/socket.io.stresstest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanyclients.sh
executable file
·68 lines (59 loc) · 1.22 KB
/
manyclients.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
#! /bin/bash
FAIL=0
VERBOSE=0
SLEEP="0.01"
# parse options
while getopts "vw:d" opt; do
case $opt in
v)
VERBOSE=1
;;
w)
SLEEP=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# remove option from args
shift $(($OPTIND - 1))
# warn if not enough args
if [ $# != 3 ]; then
echo "Usage manyclients.sh [-v] [-w seconds] 100 http(s)://host/ inputfile"
exit
fi
echo "Spawning $1 processes, waiting for $SLEEP seconds between spawns."
T="$(date +%s)"
for (( i = 0; i < $1 ; i++ ))
do
if [ $VERBOSE != "0" ]; then
./websocketclient $2 $3 &
else
./websocketclient $2 $3 > /dev/null &
fi
PIDLIST="$PIDLIST $!"
trap "kill $PIDLIST" SIGINT SIGTERM
sleep $SLEEP
done
echo -en "\033[1;31mDone spawning processes in $(($(date +%s)-T)) seconds\033[0m \n"
echo "Waiting for completion now ..."
WAIT=0
for job in $PIDLIST
do
let WAIT+=1
wait $job || let "FAIL+=1"
done
if [ "$FAIL" == "0" ];
then
echo "All clients completed succesfully."
else
echo "O noes ($FAIL) clients crashed!"
fi
T="$(($(date +%s)-T))"
echo "Time in seconds: ${T}"