Performance 在Scala中使用Gatling创建动态POST/用户调用
我正在使用Gatling生成大量用户来测试我的产品的性能问题。我需要能够动态创建具有独特字段(如“电子邮件”)的用户。所以,我正在生成一个随机数并使用它,但它并不是每次都被重新实例化,所以电子邮件只在第一次传递时是唯一的Performance 在Scala中使用Gatling创建动态POST/用户调用,performance,scala,testing,gatling,Performance,Scala,Testing,Gatling,我正在使用Gatling生成大量用户来测试我的产品的性能问题。我需要能够动态创建具有独特字段(如“电子邮件”)的用户。所以,我正在生成一个随机数并使用它,但它并不是每次都被重新实例化,所以电子邮件只在第一次传递时是唯一的 object Users { def r = new scala.util.Random; def randNumb() = r.nextInt(Integer.MAX_VALUE) val numb = randNumb() val createUser
object Users {
def r = new scala.util.Random;
def randNumb() = r.nextInt(Integer.MAX_VALUE)
val numb = randNumb()
val createUser = {
exec(http("Create User")
.post("/users")
.body(StringBody(raw"""{"email": "qa_user_$numb@company.com" }""")))
}
}
val runCreateUsers = scenario("Create Users").exec(Users.createUser)
setUp(
runCreateUsers.inject(constantUsersPerSec(10) during(1 seconds))
).protocols(httpConf)
我应该在哪里定义我的随机数?如何将其传递到createUser?使用:
val createUser=execsession=>session.setrandomN,ThreadLocalRandom.current.nexting9999999.exechttpCreate User.post/users.bodyStringBody{email:${randomN}@company.com}}我从找到的其他一些代码中拼凑出了这个。这是可行的,但我很好奇这与您的解决方案相比如何。
object Users {
val createUser = exec(http("Create User")
.post("/users")
.body(StringBody("""{"email": "qa_user_${numb}@Marqeta.com" }""")))
}
val numbers = Iterator.continually(Map("numb" -> scala.util.Random.nextInt(Int.MaxValue)))
val runCreateUsers = scenario("Create Users")
.feed(numbers)
.exec(Users.createUser)
...