Skip to content

Instantly share code, notes, and snippets.

@polarnik
Last active April 8, 2020 10:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save polarnik/d21db22114d1b7b68064202ff95d1c2d to your computer and use it in GitHub Desktop.
Save polarnik/d21db22114d1b7b68064202ff95d1c2d to your computer and use it in GitHub Desktop.
src/test/scala/io/qaload/gatling/reportExample/simulation/CloseModel_IncrementConcurrentUsers.scala
package io.qaload.gatling.reportExample.simulation
import io.gatling.core.Predef.{constantConcurrentUsers, nothingFor, _}
import io.gatling.core.structure.ScenarioBuilder
import io.qaload.gatling.reportExample.process.SimpleScenario
import io.qaload.gatling.reportExample.setting.Protocol
import scala.concurrent.duration._
import io.gatling.core.Predef._
/**
* Meta DSL to write closed increment tests (succession of several increasing levels)
*
* incrementConcurrentUsers(incrementConcurrentUsers)
* .times(numberOfSteps)
* .eachLevelLasting(levelDuration)
* .separatedByRampsLasting(rampDuration)
* .startingFrom(initialConcurrentUsers)
*
* Inject a succession of numberOfSteps levels each one
* during levelDuration
* and increasing the number of users per sec by incrementConcurrentUsers
* starting from zero or the optional initialConcurrentUsers
* and separated by optional ramps lasting rampDuration
*/
class CloseModel_IncrementConcurrentUsers extends Simulation {
def simpleScenarioWithPace(name: String, paceDuration: Duration) =
scenario(name)
.forever (
pace(100)
.exec(
SimpleScenario.simpleScenario()
)
)
def simpleScenarioWithPaceAndDuration(name: String, paceDuration: Duration, levelDuration: Duration) =
scenario(name)
.during(levelDuration) (
pace(paceDuration)
.exec(
SimpleScenario.simpleScenario()
)
)
setUp(
simpleScenarioWithPaceAndDuration("incrementConcurrentUsers", 200 millisecond, 100 second).inject(
constantConcurrentUsers(1) during (0.01 seconds),
constantConcurrentUsers(0) during (10 seconds),
incrementConcurrentUsers(1)
.times(5)
.eachLevelLasting(100 second)
.separatedByRampsLasting(0 second)
.startingFrom(1),
constantConcurrentUsers(0) during (10 seconds),
constantConcurrentUsers(1) during (0.01 seconds)
).protocols(Protocol.httpConf).throttle(
reachRps(70) in (600 seconds)
)
)
}
package io.qaload.gatling.reportExample.process
import io.gatling.core.Predef._
import io.gatling.core.structure.{ChainBuilder, ScenarioBuilder}
import io.gatling.http.Predef._
import io.qaload.gatling.util.UtilsFeed
import scala.concurrent.duration._
object SimpleScenario {
def simpleScenario(): ChainBuilder =
exec(
http("/ (GET)").get("/")
)
.exec(
http("/40x.html (GET)").get("/40x.html")
)
.exec(
http("/50x.html (GET)").get("/50x.html")
)
}
@polarnik
Copy link
Author

polarnik commented Apr 8, 2020

Снимок экрана от 2020-04-08 12-57-06

Видны скачки количества пользователей (Active Users - Virtual User - VU - правая ось на графиках - старты сценариев в сек). Это из-за того, что использовал pace с длительностью шага. Если использовать вариант с forever (тоже есть в коде), то тест не будет вечным, он будет длиться столько, сколько указано в throttle, но скачков не будет.

Снимок экрана от 2020-04-08 12-59-28

При этом количество конкрретных пользователей (выполняющихся одновременных "потоков" закрытой модели Gatling - Concurrent Users - левая ось на графике) растёт согласно профилю, от 1 до 5, без скачков. Таким образом, всего 1-5 обработчиков создают в итоге 0-70 запросов в сек.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment