Escriu per cercar…

Gatling

Gatling is a powerful, open-source load-testing tool designed to analyze and measure the performance of web applications.

Introduction

Gatling is a powerful, open-source load-testing tool designed to analyze and measure the performance of web applications. It uses a simple and expressive domain-specific language (DSL) that allows you to define complex load-testing scenarios with ease.

Performance testing is a crucial aspect of ensuring that applications can handle a large number of users and requests without faltering.

Simulation

Create a new Kotlin file in the test ?? directory of your project.

Extend the Simulation class

Gatling scripts extend Simulation. Add the class declaration:

kotlin
class BasicSimulation : Simulation() {
}

Define the HTTP protocol

Configure the target base URL and headers so Gatling knows how to talk to your application:

kotlin
class BasicSimulation : Simulation() {

    // Define HTTP configuration
    // Reference: https://docs.gatling.io/reference/script/http/protocol/
    val protocol = http
        .baseUrl("http://localhost:8080")
        .acceptHeader("application/json")
}

Key callouts:

  • http.baseUrl("http://localhost:8080") sets the server you will exercise.
  • Custom headers (user agent, accept) mimic a real browser. Adjust them when testing your own system.

Describe a scenario

Scenarios encode user journeys. Start with a single request:

kotlin
class BasicSimulation : Simulation() {
    val protocol = http
        .baseUrl("http://localhost:8080")
        .acceptHeader("application/json")

    // Define scenario
    // Reference: https://docs.gatling.io/concepts/scenario/
    val scenario = scenario("BasicSimulation")
        .exec(http("greeting david").get("/greeting?name=David"))
}

Here you:

  • Name the scenario (“BasicSimulation”).
  • Issue a GET request against /greeting with a query parameter name=David..
  • Leave room to add checks or additional steps later.

Choose an injection profile

Configure the arrival rate and duration for virtual users:

kotlin
class BasicSimulation : Simulation() {
    val protocol = http
        .baseUrl("http://localhost:8080")
        .acceptHeader("application/json")

    val scenario = scenario("TestSimulation")
        .exec(http("greeting david").get("/greeting?name=David"))

    // Define injection profile and execute the test
    // Reference:  https://docs.gatling.io/concepts/injection/
    init {
        this.setUp(scenario.injectOpen(constantUsersPerSec(50.0).during(Duration.ofSeconds(15))))
            .protocols(protocol)
    }
}

Estàs llegint una vista prèvia.

Inicia sessió amb Google per llegir la pàgina completa.

Inicia sessió amb Google

Amb qualsevol compte de Google. Només et demanarem que acceptis les condicions del servei.