Skip to content

kohofinancial/api-world-performance-testing

Repository files navigation

world-api-performance-testing

World API 2021 - Workshop - Performance Testing with Gatling

Step 1 - Requirement

  1. Installing Maven
sudo apt install maven
mvn -version
  1. Installing Java
sudo apt install default-jdk
java -version
  1. Generate the archetype
mvn archetype:generate -DarchetypeGroupId=io.gatling.highcharts -DarchetypeArtifactId=gatling-highcharts-maven-archetype -DgroupId=github.com.kohofinancial -DartifactId=world-api-performance-testing
  1. Test your project
mvn gatling:test

[ERROR] No simulations to run

Step 2 - Ping me

Let's create our first Simulation by pinging one of our service, to be sure we can connect to our service without any issues.

  1. Create a new file StatusSimulation.scala
touch src/test/scala/StatusSimulation.scala

class StatusSimulation extends Simulation { 

}
  1. Adding the HTTP Protocol
  val httpProtocol = http
    .baseUrl("<URL>") 
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")

  1. Adding the Scenario
val scn = scenario("Authorization service is alive") 
    .exec(
      http("GET - STATUS") 
        .get("_status")
    ) 
    .pause(5) 
  1. Adding the Scenario
  setUp(
    scn.inject(atOnceUsers(1)) 
  ).protocols(httpProtocol) 
  1. Run it!
mvn gatling:test
  1. Let's look to the report

Step 3 - Real time informations

  1. Enable graphite reporting in the src/test/resources/gatling.conf

  2. Create the docker-compose.yml

  3. Start all dockers

docker-compose up -d
  1. Go to the influxdb url http://localhost:8086 and import the dashboard gatling.json

  2. Run it!

mvn gatling:test
  1. Data are coming to your dashboard in realtime :party:

Step 4 - Check and Environment!

  1. Gatling supports a lot of checks around your request
          status.is(200),
          bodyString.is("\"OK\"\n")
  1. We can also use variable for the number of users in our simulation

Step 5 - Real use case!

  1. Adding a feeder
  val accountNumbers = csv("account_numbers.csv").eager.random
  1. Adding a custom body with variable
    .body(ElFileBody("authorization.json")).asJson

Step 6 - Let's play with simulation!

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)
)

Step 7 - Let's build and deploy it in Gatling Enterprise

MAVEN_OPTS="-Dusers=1 -Durl=<URL>" mvn gatling:test  -Dgatling.simulationClass=AuthorizationSimulation

mvn clean package -DskipTests

About

World API 2021 - Workshop - Performance Testing with Gatling

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published