简体   繁体   English

如何注入随机号 加特林的用户数?

[英]How to inject random no. of users in Gatling?

I would like to inject random no. 我想随机注入。 of users in Gatling. 加特林的用户数量。 For example, 例如,

For first 10 secs, 100 users 前10秒,有100位用户

For next 15 secs, 25 users, 在接下来的15秒内,有25位用户,

For next 2 secs, 1000 users and so on.. 在接下来的2秒钟内,有1000个用户,依此类推。

random time with random number of users 用户数量随机的随机时间

One complex workaround I have found is as follows: 我发现一种复杂的解决方法如下:

val r=new scala.util.Random
  setUp(
    scn.inject(

         constantUsersPerSec(10) during(10 seconds) randomized,
             constantUsersPerSec(10+r.nextInt(500)) during(15 seconds) randomized,
             constantUsersPerSec(210+r.nextInt(500)) during(25 seconds) randomized,
             constantUsersPerSec(510+r.nextInt(520)) during(55 seconds) randomized,
             constantUsersPerSec(170+r.nextInt(100)) during(5 seconds) randomized,
             constantUsersPerSec(270+r.nextInt(1010)) during(5 seconds) randomized,
             constantUsersPerSec(710+r.nextInt(5100)) during(1 minute) randomized,
             constantUsersPerSec(5+r.nextInt(40)) during(100 seconds) randomized,
             constantUsersPerSec(710+r.nextInt(5200)) during(15 seconds) randomized,
             constantUsersPerSec(0+r.nextInt(20)) during(10 seconds) randomized,


         constantUsersPerSec(10) during(10 seconds) randomized,
             constantUsersPerSec(10+r.nextInt(500)) during(15 seconds) randomized,
             constantUsersPerSec(210+r.nextInt(500)) during(25 seconds) randomized,
             constantUsersPerSec(510+r.nextInt(520)) during(55 seconds) randomized,
             constantUsersPerSec(170+r.nextInt(100)) during(5 seconds) randomized,
             constantUsersPerSec(270+r.nextInt(1010)) during(5 seconds) randomized,
             constantUsersPerSec(710+r.nextInt(5100)) during(1 minute) randomized,
             constantUsersPerSec(5+r.nextInt(40)) during(100 seconds) randomized,
             constantUsersPerSec(710+r.nextInt(5200)) during(15 seconds) randomized,

             constantUsersPerSec(1) during(10 seconds),

           ).protocols(kafkaConf))

Is there any simple way to do this? 有没有简单的方法可以做到这一点?

In other words, is there any way to inject in a loop? 换句话说,有什么方法可以注入循环吗?

PS: I tried the repeat() for a scenario, but that is a different thing altogether. PS:我尝试了一个场景的repeat() ,但这完全是另一回事。 Instead of calling once, it calls n times ie it does the action n times for every user. 它不调用一次,而是调用n次,即它为每个用户执行n次操作。

the .inject method can take an array of injection steps, so you can just use a function to generate that array .inject方法可以采用一系列注入步骤,因此您只需使用函数即可生成该数组

val r=new scala.util.Random

setUp(
    scn.inject(
        (1 to 10).map(i => constantUsersPerSec(r.nextInt(500)) during (r.nextInt(30) seconds) randomized)
    )
).protocols

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM