From 0f90115cba6c2ea5ae0d51649795ac16d25ce6b9 Mon Sep 17 00:00:00 2001 From: piotr-yuxuan Date: Thu, 28 Sep 2023 11:17:43 +0100 Subject: [PATCH] Simplistic load testing --- README.md | 15 +++++++++- pom.xml | 16 ++++++++++ .../api/ApiControllerLoadSimulationTest.java | 29 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/github/piotryuxuan/springbootplayground/api/ApiControllerLoadSimulationTest.java diff --git a/README.md b/README.md index d9093fe..59a3262 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,20 @@ Grafana dashboards: - https://grafana.com/grafana/dashboards/6756-spring-boot-statistics/ - Ideally there would be a standard dashboard for endpoints and another for database connections. -### Reference Documentation +# Load Simulation + +A load simulation is described using the Java DSL. You can run it with Gatling: + +``` zsh +mvn gatling:test +``` + +Of course it doesn't have a lot of meaning to run such simulation a local computer with a lot of different possible perturbation. An isolated, network-optimised environment in AWS is more repeatable. Still, it can give a rough, uneducated hint at the performance. Keep in mind that your local machine may have a limitation on the number of open file descriptors (`ulimit`), which further degrades the ability to simulate high load. + +A note on AWS resources: instances should be in the same availability zone (ha ha), and Elastic Fabric Adapter network interface should help make the CPU and memory the limiting factors, not the network IO. + +# Reference Documentation + For further reference, please consider the following sections: * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) diff --git a/pom.xml b/pom.xml index e684ec9..ed50144 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,13 @@ springdoc-openapi-starter-webmvc-api 2.2.0 + + + io.gatling.highcharts + gatling-charts-highcharts + 3.9.5 + test + @@ -73,6 +80,15 @@ + + io.gatling + gatling-maven-plugin + 4.5.0 + + + com.github.piotryuxuan.springbootplayground.api.ApiControllerLoadSimulationTest + + diff --git a/src/test/java/com/github/piotryuxuan/springbootplayground/api/ApiControllerLoadSimulationTest.java b/src/test/java/com/github/piotryuxuan/springbootplayground/api/ApiControllerLoadSimulationTest.java new file mode 100644 index 0000000..bc54d4a --- /dev/null +++ b/src/test/java/com/github/piotryuxuan/springbootplayground/api/ApiControllerLoadSimulationTest.java @@ -0,0 +1,29 @@ +package com.github.piotryuxuan.springbootplayground.api; + +import io.gatling.javaapi.core.*; +import io.gatling.javaapi.http.*; + +import static io.gatling.javaapi.core.CoreDsl.*; +import static io.gatling.javaapi.http.HttpDsl.*; + +import java.util.Random; + +public class ApiControllerLoadSimulationTest extends Simulation { + + HttpProtocolBuilder httpProtocol = http.baseUrl("http://localhost:8080"); + Random randomGenerator = new Random(); + + ScenarioBuilder scn = scenario("BasicSimulation") + .exec(http("request_addition").get("/api/v1/addition") + .queryParam("a", String.valueOf(randomGenerator.nextLong())) + .queryParam("b", String.valueOf(randomGenerator.nextLong()))); + + { + setUp( + scn.injectOpen( + atOnceUsers(100), + constantUsersPerSec(100).during(30), + rampUsers(1_500).during(60), + constantUsersPerSec(1_500).during(10)).protocols(httpProtocol)); + } +}