Skip to content

Commit

Permalink
Simplistic load testing
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-yuxuan committed Sep 28, 2023
1 parent ad6cba6 commit 0f90115
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>2.2.0</version>
</dependency>

<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>3.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -73,6 +80,15 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>4.5.0</version>
<configuration>
<simulationClass>
com.github.piotryuxuan.springbootplayground.api.ApiControllerLoadSimulationTest</simulationClass>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit 0f90115

Please sign in to comment.