autoscaling load generation

This commit is contained in:
Steve Waterworth
2019-06-03 12:32:57 +01:00
parent be5d74dbc5
commit 4f53be999e
3 changed files with 91 additions and 27 deletions

View File

@@ -1,16 +1,20 @@
# Load Generation
This is deliberately not part of docker-compose.yaml to give the option of running the sample application without load.
This is deliberately not part of docker-compose.yaml to give the option of running the sample application without load. The image is available on Docker Hub but if you want to build your own, run:
$ ./build.sh <push>
```shell
$ ./build.sh <push>
```
Will build with image and optionally push it.
$ ./load-gen.sh
```shell
$ ./load-gen.sh
```
Runs the load generation script against the application started with `docker-compose up` . There are various command line options to configure the load.
Alternatively, you can run the Container from Dockerhub directly on one of the nodes having access to the web service:
Alternatively, you can run the Container from Docker Hub directly on one of the nodes having access to the web service:
```shell
$ docker run \
@@ -19,7 +23,8 @@ $ docker run \
--name="loadgen" \
--network=host \
-e "HOST=http://host:8080/"
-e "HUM_CLIENTS=1" \
-e "NUM_CLIENTS=5" \
-e "RUN_TIME=1h30m" \
-e "ERROR=1" \
-e "SILENT=1" \
robotshop/rs-load
@@ -29,6 +34,7 @@ Set the following environment variables to configure the load:
* HOST - The target for the load e.g. http://host:8080/
* NUM_CLIENTS - How many simultaneous load scripts to run, the bigger the number the bigger the load. The default is 1
* RUN_TIME - For NUM_CLIENTS greater than 1 the duration to run. If not set, load is run for ever with NUM_CLIENTS. See below.
* ERROR - Set this to 1 to have erroroneous calls made to the payment service.
* SILENT - Set this to 1 to surpress the very verbose output from the script. This is a good idea if you're going to run load for more than a few minutes.
@@ -40,7 +46,7 @@ To run the load test in Kubernetes, apply the `K8s/load-deployment.yaml` configu
$ kubectl -n robot-shop apply -f K8s/load-deployment.yaml
```
If you want to enable auto-scaling on relevant components (non-databases), just run the script in the autoscaling directory. However you will first need to make sure a [metrics-server](https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/) is running in your cluster, this enables the Horizontal Pod Autoscaler to know about the CPU and memory usage of the pods. From Kubernetes version 1.8, a `metrics-serer` deployment should be configured by default, run the command below to check.
If you want to enable auto-scaling on relevant components (non-databases), just run the script in the autoscaling directory. However you will first need to make sure a [metrics-server](https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/) is running on your cluster, this enables the Horizontal Pod Autoscaler to know about the CPU and memory usage of the pods. From Kubernetes version 1.8, a `metrics-serer` deployment should be configured by default, run the command below to check.
```shell
$ kubectl -n kube-system get deployment
@@ -52,3 +58,13 @@ The autoscaling is installed with:
$ K8s/autoscale.sh
```
To get Kubernetes to automatically scale up/down the pods the load can be varied over time with:
```shell
$ ./load-gen.sh \
-h http://host:port/
-n 10 \
-t 1h30m
```
The load will be run with `10` clients for `1h30m` before dropping down to `1` client for `1h30m` then looping back to `10` clients etc.

View File

@@ -1,33 +1,41 @@
#!/bin/sh
# set -x
if [ -z "$HOST" ]
then
echo "HOST env not set"
exit 1
fi
TEST=$(echo "$HOST" | egrep '^http://[a-z0-9]+')
if [ -z "$TEST" ]
if [ $RUN_TIME -eq 0 -o $NUM_CLIENTS -eq 1 ]
then
echo "Host must start with http://"
exit 1
unset RUN_TIME
fi
if echo "$NUM_CLIENTS" | egrep -q '^[0-9]+$'
echo "Starting load with $NUM_CLIENTS clients"
if [ $NUM_CLIENTS -gt 1 -a -n "$RUN_TIME" ]
then
CLIENTS=${NUM_CLIENTS:-1}
else
echo "$NUM_CLIENTS is not a number falling back to 1"
CLIENTS=1
echo "Looping every $RUN_TIME"
fi
echo "Starting load with $CLIENTS clients"
echo "ERROR $ERROR"
if [ "$SILENT" -eq 1 ]
then
locust -f robot-shop.py --host "$HOST" --no-web -c $CLIENTS -r 1 > /dev/null 2>&1
else
locust -f robot-shop.py --host "$HOST" --no-web -c $CLIENTS -r 1
fi
while true
do
for CLIENTS in $NUM_CLIENTS 1
do
if [ -n "$RUN_TIME" ]
then
TIME="-t $RUN_TIME"
else
unset TIME
fi
echo "Starting $CLIENTS clients for ${RUN_TIME:-ever}"
if [ "$SILENT" -eq 1 ]
then
locust -f robot-shop.py --host "$HOST" --no-web -r 1 -c $CLIENTS $TIME > /dev/null 2>&1
else
locust -f robot-shop.py --host "$HOST" --no-web -r 1 -c $CLIENTS $TIME
fi
done
done

View File

@@ -6,6 +6,9 @@
# The bigger the number the more requests, the bigger the load
NUM_CLIENTS=1
# Time to run with NUM_CLIENTS e.g. 1h
RUN_TIME=0
# HOST where Stan's Robot Shop web UI is running
HOST="http://localhost:8080"
@@ -16,7 +19,16 @@ ERROR=0
DAEMON="-it"
SILENT=0
USAGE="\nloadgen.sh\n\te - error flag\n\td - run in background\n\tn - number of clients\n\th - target host\n"
USAGE="\
loadgen.sh
e - error flag
d - run in background
n - number of clients
t - time to run n clients
h - target host
"
if [ ! -f ../.env ]
then
@@ -30,7 +42,7 @@ eval $(egrep '[A-Z]+=' ../.env)
echo "Repo $REPO"
echo "Tag $TAG"
while getopts 'edn:h:' OPT
while getopts 'edn:t:h:' OPT
do
case $OPT in
e)
@@ -42,12 +54,39 @@ do
;;
n)
NUM_CLIENTS=$OPTARG
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
;;
h)
HOST=$OPTARG
if echo "$HOST" | egrep '^http://[a-z0-9]+'
then
echo "Host $HOST"
else
echo "Host must start http://"
echo "$USAGE"
exit 1
fi
;;
*)
echo -e "$USAGE"
echo "$USAGE"
exit 1
;;
esac
@@ -60,6 +99,7 @@ docker run \
--network=host \
-e "HOST=$HOST" \
-e "NUM_CLIENTS=$NUM_CLIENTS" \
-e "RUN_TIME=$RUN_TIME" \
-e "SILENT=$SILENT" \
-e "ERROR=$ERROR" \
${REPO}/rs-load:${TAG}