Gatling 的可变 rampUp
Variable rampUp with Gatling
我尝试用多种 "breaks" 和 "atOnceUsers" 进行注射。
我没有在文档中找到好的解决方案。
我的方法是用本地计数器创建一个名为"getNextNumber()"的函数,以增加"atOnceUsers"的数量,但该函数一开始只调用了一次。
有什么想法吗?
我的代码:
class TestCombinationGetFiles extends Simulation {
var counter: Int =1
def getNextNumber():Int = {
counter+= 1
return counter
}
val Get20Files = scenario("get20Files")
.feed(UuidFeeder.feeder)
.exec(WebAuth.AuthenticateUser)
.pause(30)
.exec(WebCloudContent.GoToTestFolder20)
val Get10Files = scenario("get10Files").feed(UuidFeeder.feeder)
.exec(WebAuth.AuthenticateUser)
.pause(15)
.exec(WebCloudContent.GoToTestFolder10)
val loadFolder20TestRamp =
scenario("loadFolder20TestRamp").exec(WebAuthSwisscom.AuthenticateUser,
WebCloudContentSwisscom.GoToTestFolder20)
setUp(Get20Files.inject(
splitUsers(36) into(
atOnceUsers(getNextNumber()))
separatedBy(30 seconds))
/* messy Code with correct functionality
atOnceUsers(1),
nothingFor(30 seconds),
atOnceUsers(2),
nothingFor(30 seconds),
atOnceUsers(3),
nothingFor(30 seconds),
atOnceUsers(4),
nothingFor(30 seconds),
atOnceUsers(5),
nothingFor(30 seconds),
atOnceUsers(6),
nothingFor(30 seconds),
atOnceUsers(7),
nothingFor(30 seconds),
atOnceUsers(8),
nothingFor(30 seconds))
*/
,
Get10Files.inject(
splitUsers(16) into(
atOnceUsers(1))
separatedBy(15 seconds))
).protocols(WebSetUp.httpProtocol)
}
我想您发现了 Gatling 中缺少的功能!我将进一步开发它并向 Gatling 团队提交拉取请求以(希望)将其纳入项目,但与此同时,您可以通过提供自己的自定义功能来获得所需的功能 InjectionStep
实施 - 只需将其粘贴到 Simulation
文件的顶部:
import io.gatling.core.controller.inject._
import scala.concurrent.duration._
case class AtOnceIncrementalInjection(users: Int) extends InjectionStep {
require(users > 0, "The number of users must be a strictly positive value")
var count = users
override def chain(chained: Iterator[FiniteDuration]): Iterator[FiniteDuration] = {
val currentUsers = count
count += 1
Iterator.continually(0 milliseconds).take(currentUsers) ++ chained
}
}
def atOnceIncrementalUsers(initialUsers:Int) = AtOnceIncrementalInjection(initialUsers)
这基本上就是您尝试用 atOnceUsers
做的事情,但关键区别在于计数是 在 中 chain
方法,它将得到您想要的递增行为,因为 chain
将被调用 每次 Gatling 决定是时候发送一些请求了。
现在您可以像以前一样使用辅助函数 atOnceUsers
:
splitUsers(36) into(
atOnceIncrementalUsers(1))
separatedBy(30 seconds))
我尝试用多种 "breaks" 和 "atOnceUsers" 进行注射。 我没有在文档中找到好的解决方案。
我的方法是用本地计数器创建一个名为"getNextNumber()"的函数,以增加"atOnceUsers"的数量,但该函数一开始只调用了一次。
有什么想法吗?
我的代码:
class TestCombinationGetFiles extends Simulation {
var counter: Int =1
def getNextNumber():Int = {
counter+= 1
return counter
}
val Get20Files = scenario("get20Files")
.feed(UuidFeeder.feeder)
.exec(WebAuth.AuthenticateUser)
.pause(30)
.exec(WebCloudContent.GoToTestFolder20)
val Get10Files = scenario("get10Files").feed(UuidFeeder.feeder)
.exec(WebAuth.AuthenticateUser)
.pause(15)
.exec(WebCloudContent.GoToTestFolder10)
val loadFolder20TestRamp =
scenario("loadFolder20TestRamp").exec(WebAuthSwisscom.AuthenticateUser,
WebCloudContentSwisscom.GoToTestFolder20)
setUp(Get20Files.inject(
splitUsers(36) into(
atOnceUsers(getNextNumber()))
separatedBy(30 seconds))
/* messy Code with correct functionality
atOnceUsers(1),
nothingFor(30 seconds),
atOnceUsers(2),
nothingFor(30 seconds),
atOnceUsers(3),
nothingFor(30 seconds),
atOnceUsers(4),
nothingFor(30 seconds),
atOnceUsers(5),
nothingFor(30 seconds),
atOnceUsers(6),
nothingFor(30 seconds),
atOnceUsers(7),
nothingFor(30 seconds),
atOnceUsers(8),
nothingFor(30 seconds))
*/
,
Get10Files.inject(
splitUsers(16) into(
atOnceUsers(1))
separatedBy(15 seconds))
).protocols(WebSetUp.httpProtocol)
}
我想您发现了 Gatling 中缺少的功能!我将进一步开发它并向 Gatling 团队提交拉取请求以(希望)将其纳入项目,但与此同时,您可以通过提供自己的自定义功能来获得所需的功能 InjectionStep
实施 - 只需将其粘贴到 Simulation
文件的顶部:
import io.gatling.core.controller.inject._
import scala.concurrent.duration._
case class AtOnceIncrementalInjection(users: Int) extends InjectionStep {
require(users > 0, "The number of users must be a strictly positive value")
var count = users
override def chain(chained: Iterator[FiniteDuration]): Iterator[FiniteDuration] = {
val currentUsers = count
count += 1
Iterator.continually(0 milliseconds).take(currentUsers) ++ chained
}
}
def atOnceIncrementalUsers(initialUsers:Int) = AtOnceIncrementalInjection(initialUsers)
这基本上就是您尝试用 atOnceUsers
做的事情,但关键区别在于计数是 在 中 chain
方法,它将得到您想要的递增行为,因为 chain
将被调用 每次 Gatling 决定是时候发送一些请求了。
现在您可以像以前一样使用辅助函数 atOnceUsers
:
splitUsers(36) into(
atOnceIncrementalUsers(1))
separatedBy(30 seconds))