Configuring simulation settings and tuning performance
Gatling provides a number of configuration options that allow you to tune your simulations to reflect the desired load on your system. Some of the most important configuration options include:
Number of users: This setting determines how many users will be simulated in the test scenario. You can specify a fixed number of users or ramp up to a certain number of users over a specified period of time.
Ramp-up period: This setting determines the amount of time it takes to ramp up to the full number of users. You can specify a fixed ramp-up period or ramp up the number of users over a specified duration.
Test duration: This setting determines how long the test will run. You can specify a fixed duration or have the test run until a specified number of requests have been completed.
Pauses between requests: You can specify the amount of time to pause between requests to simulate think time. This helps to more closely reflect real-world usage patterns.
Here's an example of how you might configure a Gatling simulation to reflect a desired load:
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class BasicSimulation extends Simulation {
val httpProtocol = http
.baseUrl("http://localhost:8080")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0")
val scn = scenario("BasicSimulation")
.exec(http("request_1")
.get("/"))
.pause(5)
.exec(http("request_2")
.get("/search?q=gatling"))
.pause(1)
.exec(http("request_3")
.get("/cart"))
.pause(2)
.exec(http("request_4")
.post("/purchase")
.formParam("itemId", "12345"))
.pause(3)
.exec(http("request_5")
.get("/confirmation"))
setUp(
scn.inject(
rampUsers(100) during (10 seconds),
constantUsersPerSec(50) during (20 seconds),
rampUsersPerSec(10) to 20 during (10 seconds)
)
).protocols(httpProtocol)
.maxDuration(30 seconds)
}
In this example, we're using the rampUsers
method to ramp up to 100 users over a 10-second period. Then, we use the constantUsersPerSec
method to maintain a constant rate of 50 users per second for the next 20 seconds. Finally, we use the rampUsersPerSec
method to ramp up from 10 users per second to 20 users per second over a 10-second period.
We also use the maxDuration
method to specify that the test should run for a maximum of 30 seconds. This ensures
Leave a Comment