2015-08-25 28 views
1

我最近開始使用gatling進行性能和負載測試。根據他們的文檔,有幾種發送併發請求的方式,例如:Gatling測試增加每秒鐘不變用戶數下面的模式

rampUsersPerSec(1) to(100) during(1 minute)應該每秒增加線性用戶數量,但它對它有很大的隨機性。我想要做的是每秒發送一個固定數量的請求,然後暫停,然後再增加一個用戶,然後重複。沿着線的東西:

import io.gatling.core.Predef._ 
import io.gatling.http.Predef._ 

class PricesSimulation extends Simulation { 
    // ... 
    // ... 

    object GetPrices { 
    // ... 
    } 

    val httpConf = http.baseURL("https://...") 
    val scn = scenario("scenario1").exec(...) 

    setUp(
    scn.inject(
     constantUsersPerSec(1) during(5 seconds), 
     nothingFor(5 seconds), 
     constantUsersPerSec(2) during(10 seconds), 
     nothingFor(5 seconds), 
     constantUsersPerSec(3) during(10 seconds), 
     nothingFor(5 seconds), 
     constantUsersPerSec(4) during(10 seconds), 
     nothingFor(5 seconds), 
     constantUsersPerSec(5) during(10 seconds) 
     // ... 
     constantUsersPerSec(100) during(10 seconds) 
    ).protocols(httpConf) 
) 
} 

所以基本上我想在setUp減少一切for循環,我由一個(或等值)增加constantUsersPerSec的ARG。然而,我的斯卡拉知識是非常有限的,我失敗慘了...

回答

0

試試這個。

val steps = (constantUsersPerSec(1) during(5 seconds)) :: (2 to 100).toList.flatMap(i => 
    List(
    nothingFor(5 seconds), 
    constantUsersPerSec(i) during(10 seconds) 
) 
) 

setUp(steps: _*).protocols(httpConf)