带有Gatling的可变rampUp

时间:2015-05-04 15:20:43

标签: scala gatling

我尝试注射各种各样的"休息"和" 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)
}

1 个答案:

答案 0 :(得分:1)

我认为你在加特林发现了一个缺失的功能!我将更多地开发这个并向Gatling团队提交拉取请求(希望)将其纳入项目,但与此同时,您可以通过提供自己的自定义{{{{{{ 1}}实现 - 只需将其粘贴到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每次都会被称为 Gatling决定发送一些请求的时间。

现在您可以像使用chain

一样使用辅助函数
atOnceUsers
相关问题