Home > OS >  Why first Gatling request is slower?
Why first Gatling request is slower?

Time:03-21

I have a Gatling scenario where I'm calling the Gatling demo app endpoint. I noticed that the first request is taking a higher time to respond to. For example:

public class OneEndpointSimulation extends Simulation {

HttpProtocolBuilder httpProtocol = http
        .baseUrl("http://computer-database.gatling.io")
        .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:31.0) Gecko/20100101 Firefox/31.0");

ScenarioBuilder scn = scenario("BasicSimulation")
        .repeat(10)
        .on(
                exec(http("request_1")
                        .get("/computers")));

{
    setUp(scn.injectOpen(atOnceUsers(1))
    ).protocols(httpProtocol);
}
    
}

Screen of Gatling report

Here is simulation.log file result:

RUN activitydatabase.OneEndpointSimulation  oneendpointsimulation   1647472671275       3.7.5
USER    BasicSimulation START   1647472672290
REQUEST     request_1   1647472672322   1647472672578   OK   
REQUEST     request_1   1647472672614   1647472672740   OK   
REQUEST     request_1   1647472672742   1647472672867   OK   
REQUEST     request_1   1647472672868   1647472672992   OK   
REQUEST     request_1   1647472672994   1647472673121   OK   
REQUEST     request_1   1647472673123   1647472673244   OK   
REQUEST     request_1   1647472673246   1647472673368   OK   
REQUEST     request_1   1647472673371   1647472673492   OK   
REQUEST     request_1   1647472673494   1647472673616   OK   
REQUEST     request_1   1647472673618   1647472673741   OK   
USER    BasicSimulation END 1647472673748

Is there any way to speed up the first request?

CodePudding user response:

You're getting it wrong, this is expected.

Because of the way your test is designed, the first request takes more time because it has more work to do:

  • perform the DNS resolution
  • open the HTTP connection

The next requests for this single virtual user will skip this extra work because:

  • the DNS resolution will be in cache
  • they will reuse the same keep-alive HTTP connection
  • Related