Setting Gatling to send requests based on percentage/ratios?

321
May 04, 2017, at 11:12 PM

I want to setup Gatling so that in one setup, I can send 3000 requests, of which 95% will use one test file, and 5% another test file. These files are retrieved as json files (called 'userFeeder' in below code. Can Gatling support the above scenario?

The code is currently as follows, which works for a request per second approach, but needs amending.

class AddUserSimulation extends Simulation {
  private val conf = ConfigFactory.load() //loads a setup file of parameters
  private val TOKEN_VALUE = "tokenvalue"
  private val userFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser.json")
  val httpConf = http
    .baseURL(conf.getString("api.gateway.url")) // Here is the root for all relative URLs
    .header("Referer", conf.getString("referer"))
    .header("Cache-Control", "no-cache")
    .contentTypeHeader("application/json")
  val Login = new ADFSAuthentication Login
  val scnAPI = scenario("test add User") // A scenario is a chain of requests and pauses
    .feed(userFeeder.circular)
    .exec(Login.process)
    .repeat(conf.getInt("repeat.count")) {
        exec(http("test add User")
        .post("/" + conf.getString("environment") + "/users/")
        .body(StringBody("${payload}")).asJSON
        .header("Authorization", "Bearer ${"+TOKEN_VALUE+"}")
    .check(status.is(200)))
    .pause(conf.getInt("execution.pause"))
    }
  setUp(scnAPI.inject(constantUsersPerSec(11) during(30 minutes)).protocols(httpConf)) 
}

Any help is greatly appreciated.

Answer 1

Sure! First set up your two feeders. Then set up two scenarios, one using the first feeder, one using the second feeder. Finally setUp both with the number of users you wish (corresponding to your distribution).

The code could look something like this:

private val firstFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser.json")
private val secondFeeder =  jsonFile("/" + conf.getString("environment") + "/testaddUser2.json")
val scnAPI = scenario("test add User")
    .feed(firstFeeder)
    //...
val scnAPI2 = scenario("second test add User")
    .feed(secondFeeder)
    //...
setUp(scnAPI.inject(constantUsersPerSec(95) during(30 minutes)).protocols(httpConf)) 
setUp(scnAPI2.inject(constantUsersPerSec(5) during(30 minutes)).protocols(httpConf)) 

Note: This will not create exactly 3000 requests but I think you get the idea.

READ ALSO
Able to destroy Runtime.getRuntime().exec process but not a ProcessBuilder made process

Able to destroy Runtime.getRuntime().exec process but not a ProcessBuilder made process

I have java class (calljava) which uses a system call to a perl script in a new thread

310
Load themes files from external to playframwork app

Load themes files from external to playframwork app

We have to configure the static content ie

320
Remove the row with a specific value from excel in javacode

Remove the row with a specific value from excel in javacode

I want to remove all the rows from the excel having value 1 in column F and save it in a new excel in java codeMy java code is below

351
Java socketChannel to detect disorderly closed connection

Java socketChannel to detect disorderly closed connection

I know that a SocketChannel is "notified" about an orderly closed connection by receiving "-1" after calling read()

441