我想注入随机号。加特林的用户数量。 例如,
头10秒内,有100位用户
接下来的15秒内,有25位用户
接下来2秒钟内,将有1000个用户,依此类推。
用户数量随机的随机时间
我发现一个复杂的解决方法如下:
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))
有没有简单的方法可以做到这一点?
换句话说,有什么方法可以注入循环吗?
P.S:我尝试使用repeat()
进行场景编程,但这完全是另一回事。它不会调用一次,而是会调用 n 次,即为每个用户执行n
次操作。
答案 0 :(得分:1)
.inject方法可以采用一系列注入步骤,因此您只需使用函数即可生成该数组
C