Files
robot-shop/load-gen/load-gen.sh

120 lines
2.6 KiB
Bash
Raw Permalink Normal View History

2018-02-06 15:51:43 -05:00
#!/bin/sh
2018-10-22 15:43:40 +01:00
# set -x
2018-04-24 17:35:44 +01:00
# Changing the NUM_CLIENTS environment variable varies the load on the application
# The bigger the number the more requests, the bigger the load
2018-10-22 15:43:40 +01:00
NUM_CLIENTS=1
2019-06-03 12:32:57 +01:00
# Time to run with NUM_CLIENTS e.g. 1h
RUN_TIME=0
2018-10-22 15:43:40 +01:00
# HOST where Stan's Robot Shop web UI is running
HOST="http://localhost:8080"
2018-04-24 17:35:44 +01:00
2019-02-11 16:18:15 +00:00
# Error flag
ERROR=0
# Verbose mode
LOAD_DEBUG=1
2019-02-11 16:18:15 +00:00
# Daemon flag
DAEMON="-it"
SILENT=0
2019-06-03 12:32:57 +01:00
USAGE="\
loadgen.sh
e - error flag
v - verbose mode. It implies the setting of LOAD_DEBUG and of error flag. The load debug will still be printed in the stdout, even if the stdout is suppressed.
d - run in background. It implies the setting of SILENT mode, so the stdout will not be floaded. If -v is used, the load debug will still be printed in the stdout, even if the stdout is suppressed.
2019-06-03 12:32:57 +01:00
n - number of clients
t - time to run n clients
h - target host
"
2019-02-11 16:18:15 +00:00
2018-10-22 15:43:40 +01:00
if [ ! -f ../.env ]
then
echo "Please run this script from the load-gen directory"
exit 1
fi
2018-07-24 11:07:21 +01:00
2018-03-21 08:40:42 +00:00
# get the tag info
eval $(egrep '[A-Z]+=' ../.env)
echo "Repo $REPO"
echo "Tag $TAG"
2018-02-06 15:51:43 -05:00
while getopts 'edvn:t:h:' OPT
2019-02-11 16:18:15 +00:00
do
case $OPT in
e)
ERROR=1
;;
v)
LOAD_DEBUG=1
ERROR=1
;;
2019-02-11 16:18:15 +00:00
d)
DAEMON="-d"
SILENT=1
;;
n)
NUM_CLIENTS=$OPTARG
2019-06-03 12:32:57 +01:00
if echo "$NUM_CLIENTS" | egrep -q '^[0-9]+$'
then
CLIENTS=${NUM_CLIENTS:-1}
echo "Running $CLIENTS clients"
else
echo "$NUM_CLIENTS is not a number falling back to 1"
CLIENTS=1
fi
;;
t)
RUN_TIME=$OPTARG
if echo "$RUN_TIME" | egrep -q '^([0-9]+h)?([0-9]+m)?$'
then
echo "Run time set to $RUN_TIME"
else
echo "Time format 1h30m"
echo "$USAGE"
exit 1
fi
2019-02-11 16:18:15 +00:00
;;
h)
HOST=$OPTARG
2019-06-03 12:32:57 +01:00
if echo "$HOST" | egrep '^http://[a-z0-9]+'
then
echo "Host $HOST"
else
echo "Host must start http://"
echo "$USAGE"
exit 1
fi
2019-02-11 16:18:15 +00:00
;;
*)
2019-06-03 12:32:57 +01:00
echo "$USAGE"
2019-02-11 16:18:15 +00:00
exit 1
;;
esac
done
2019-01-11 10:30:37 +00:00
rm -rf logs/*
2019-02-11 16:18:15 +00:00
docker run \
$DAEMON \
--name loadgen \
--volume ${PWD}/logs:/load/logs \
--volume ${PWD}/utilities:/load/utilities \
2019-02-11 16:18:15 +00:00
--rm \
--network=host \
-e "HOST=$HOST" \
-e "NUM_CLIENTS=$NUM_CLIENTS" \
2019-06-03 12:32:57 +01:00
-e "RUN_TIME=$RUN_TIME" \
2019-02-11 16:18:15 +00:00
-e "SILENT=$SILENT" \
-e "ERROR=$ERROR" \
-e "LOAD_DEBUG=$LOAD_DEBUG" \
2019-02-11 16:18:15 +00:00
${REPO}/rs-load:${TAG}
2018-02-06 15:51:43 -05:00