World API 2021 - Workshop - Performance Testing with Gatling
- Installing Maven
sudo apt install maven
mvn -version
- Installing Java
sudo apt install default-jdk
java -version
- Generate the archetype
mvn archetype:generate -DarchetypeGroupId=io.gatling.highcharts -DarchetypeArtifactId=gatling-highcharts-maven-archetype -DgroupId=github.com.kohofinancial -DartifactId=world-api-performance-testing
- Test your project
mvn gatling:test
[ERROR] No simulations to run
Let's create our first Simulation by pinging one of our service, to be sure we can connect to our service without any issues.
- Create a new file
StatusSimulation.scala
touch src/test/scala/StatusSimulation.scala
class StatusSimulation extends Simulation {
}
- Adding the HTTP Protocol
val httpProtocol = http
.baseUrl("<URL>")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
- Adding the Scenario
val scn = scenario("Authorization service is alive")
.exec(
http("GET - STATUS")
.get("_status")
)
.pause(5)
- Adding the Scenario
setUp(
scn.inject(atOnceUsers(1))
).protocols(httpProtocol)
- Run it!
mvn gatling:test
- Let's look to the report
-
Enable
graphite
reporting in thesrc/test/resources/gatling.conf
-
Create the
docker-compose.yml
-
Start all dockers
docker-compose up -d
-
Go to the influxdb url
http://localhost:8086
and import the dashboardgatling.json
-
Run it!
mvn gatling:test
- Data are coming to your dashboard in realtime :party:
- Gatling supports a lot of checks around your request
status.is(200),
bodyString.is("\"OK\"\n")
- We can also use variable for the number of users in our simulation
- Adding a feeder
val accountNumbers = csv("account_numbers.csv").eager.random
- Adding a custom body with variable
.body(ElFileBody("authorization.json")).asJson
Let's change the type of simulation:
- Closed systems, where you control the concurrent number of users
- Open systems, where you control the arrival rate of users
setUp(
scn.inject(
nothingFor(4.seconds),
atOnceUsers(50),
rampUsers(50).during(1.minutes),
rampUsersPerSec(10).to(20).during(1.minutes).randomized
).protocols(httpProtocol)
)
MAVEN_OPTS="-Dusers=1 -Durl=<URL>" mvn gatling:test -Dgatling.simulationClass=AuthorizationSimulation
mvn clean package -DskipTests