From 27ba6cecb19a36c14cd239cb2ead5329c129b2af Mon Sep 17 00:00:00 2001 From: Parya Moinzadeh Date: Mon, 25 Feb 2019 18:58:25 -0800 Subject: [PATCH] Changing the Dockerfile and the directories so that we have a single image and a more flat sctucture. --- test/load/{fleet-autoscaling => }/Dockerfile | 2 +- test/load/README.md | 39 +++++++++++++------ test/load/gameserver-allocation/Dockerfile | 24 ------------ .../gameserver-allocation/locust-files/run.sh | 18 --------- .../fleet_autoscaling.py} | 0 .../gameserver_allocation.py} | 0 .../locust-files => }/run.sh | 2 +- 7 files changed, 30 insertions(+), 55 deletions(-) rename test/load/{fleet-autoscaling => }/Dockerfile (93%) delete mode 100644 test/load/gameserver-allocation/Dockerfile delete mode 100644 test/load/gameserver-allocation/locust-files/run.sh rename test/load/{fleet-autoscaling/locust-files/locustfile.py => locust-files/fleet_autoscaling.py} (100%) rename test/load/{gameserver-allocation/locust-files/locustfile.py => locust-files/gameserver_allocation.py} (100%) rename test/load/{fleet-autoscaling/locust-files => }/run.sh (90%) diff --git a/test/load/fleet-autoscaling/Dockerfile b/test/load/Dockerfile similarity index 93% rename from test/load/fleet-autoscaling/Dockerfile rename to test/load/Dockerfile index 38ff120fee..8c41a4864d 100644 --- a/test/load/fleet-autoscaling/Dockerfile +++ b/test/load/Dockerfile @@ -20,5 +20,5 @@ EXPOSE 8089 5557 5558 RUN mkdir /etc/service/locust COPY /locust-files ./ -COPY /locust-files/run.sh /etc/service/locust/run +COPY /run.sh /etc/service/locust/run RUN chmod +x /etc/service/locust/run diff --git a/test/load/README.md b/test/load/README.md index aa685464a3..00298e94a8 100644 --- a/test/load/README.md +++ b/test/load/README.md @@ -1,34 +1,51 @@ -# Load Testing +# Load and performance tests -Load tests aim to test the performance of the system under heavy load. Game server allocation is an example where multiple parallel operations should be tested. +Load tests aim to test the performance of the system under heavy load. For Agones, game server allocation is an example where heavy load and multiple parallel operations can be envisioned. Locust provides a good framework for testing a system under heavy load. It provides a light-weight mechanism to launch thousands of workers that run a given test. -## Build and run test +The goal of performance tests is to provide metrics on various operations. For +Agones, fleet scaling is a good example where performance metrics are useful. +Similar to laod tests, Locust can be used for performance tests with the main +difference being the number of workers that are launched. + +## Build and run tests Prerequisites: - Docker. - A running k8s cluster. -- Have kubeconfig file ready. Load tests are written using Locust. These tests are also integrated with Graphite and Grafana for storage and visualization of the results. -### Running Load tests using Locust on your local machine +### Running load tests using Locust on your local machine -Start a proxy to the Kubernetes API server: +This test uses the HTTP proxy on the local machine to access the k8s API. The default port for the proxy is 8001. To start a proxy to the Kubernetes API +server: ``` kubectl proxy [--port=PORT] & ``` -The default port for the proxy is 8001. +Next, we need to build the Docker images and run the container: ``` docker build -t locust-files . -docker run --rm --network="host" -e "TARGET_HOST=http://127.0.0.1:8001" locust-files:latest ``` The above will build a Docker container to install Locust, Grafana, and Graphite and will configure -them. The test uses the HTTP proxy on the local machine to access the k8s API. +them. To run Locust tests for game server allocation: + +``` +docker run --rm --network="host" -e "LOCUST_FILE=gameserver_allocation.py -e "TARGET_HOST=http://127.0.0.1:8001" locust-files:latest +``` + +To run Locust tests for fleet autoscaling: + +``` +docker run --rm --network="host" -e "LOCUST_FILE=fleet_autoscaling.py -e "TARGET_HOST=http://127.0.0.1:8001" locust-files:latest +``` + +NOTE: The Docker network host only works for Linux. For macOS and Windows you can use the special DNS name host.docker.internal. + +After running the Docker container you can access Locust on port 8089 of your local machine. When running Locust tests, it is recommended to use the same value for number of users and hatch rate. For game server allocation, these numbers can be large, but for fleet autoscaling a single user is sufficient. -After running the Docker container you can access Locust on port 8089 of your local machine. -Grafana will be available on port 80, and Graphite on port 81. \ No newline at end of file +Grafana will be available on port 80, and Graphite on port 81. diff --git a/test/load/gameserver-allocation/Dockerfile b/test/load/gameserver-allocation/Dockerfile deleted file mode 100644 index 38ff120fee..0000000000 --- a/test/load/gameserver-allocation/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2018 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM hopsoft/graphite-statsd - -# Locust -RUN pip install locustio -EXPOSE 8089 5557 5558 - -RUN mkdir /etc/service/locust -COPY /locust-files ./ -COPY /locust-files/run.sh /etc/service/locust/run -RUN chmod +x /etc/service/locust/run diff --git a/test/load/gameserver-allocation/locust-files/run.sh b/test/load/gameserver-allocation/locust-files/run.sh deleted file mode 100644 index d884db23ef..0000000000 --- a/test/load/gameserver-allocation/locust-files/run.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# TAKEN FROM: https://github.com/GoogleCloudPlatform/distributed-load-testing-using-kubernetes/blob/master/docker-image/locust-tasks/run.s - -LOCUST="/usr/local/bin/locust" -LOCUS_OPTS="-f locustfile.py --host=$TARGET_HOST" -LOCUST_MODE=${LOCUST_MODE:-standalone} - -if [[ "$LOCUST_MODE" = "master" ]]; then - LOCUS_OPTS="$LOCUS_OPTS --master" -elif [[ "$LOCUST_MODE" = "worker" ]]; then - LOCUS_OPTS="$LOCUS_OPTS --slave --master-host=$LOCUST_MASTER" -fi - -echo "$LOCUST $LOCUS_OPTS" - -$LOCUST $LOCUS_OPTS - diff --git a/test/load/fleet-autoscaling/locust-files/locustfile.py b/test/load/locust-files/fleet_autoscaling.py similarity index 100% rename from test/load/fleet-autoscaling/locust-files/locustfile.py rename to test/load/locust-files/fleet_autoscaling.py diff --git a/test/load/gameserver-allocation/locust-files/locustfile.py b/test/load/locust-files/gameserver_allocation.py similarity index 100% rename from test/load/gameserver-allocation/locust-files/locustfile.py rename to test/load/locust-files/gameserver_allocation.py diff --git a/test/load/fleet-autoscaling/locust-files/run.sh b/test/load/run.sh similarity index 90% rename from test/load/fleet-autoscaling/locust-files/run.sh rename to test/load/run.sh index d884db23ef..5a5bdb769b 100644 --- a/test/load/fleet-autoscaling/locust-files/run.sh +++ b/test/load/run.sh @@ -3,7 +3,7 @@ # TAKEN FROM: https://github.com/GoogleCloudPlatform/distributed-load-testing-using-kubernetes/blob/master/docker-image/locust-tasks/run.s LOCUST="/usr/local/bin/locust" -LOCUS_OPTS="-f locustfile.py --host=$TARGET_HOST" +LOCUS_OPTS="-f $LOCUST_FILE --host=$TARGET_HOST" LOCUST_MODE=${LOCUST_MODE:-standalone} if [[ "$LOCUST_MODE" = "master" ]]; then