如何使用Jmeter在循环中运行2个线程组?

时间:2020-07-06 08:23:09

标签: jmeter

我有2个线程组

  1. 授权: 用户登录获取承载令牌-我在BeanShell脚本中将一个属性设置为“承载”
  2. Api请求: 在Beanshell预处理程序中,m从授权中获取承载令牌并在请求中进行设置

这两个线程在用户数为1时均可正常工作 现在我想为5个用户发送5个Api请求

例如

var authorizationusercnt = 5;
var apiRequestusercnt = 5;
for(i=0;i<authorizationusercnt;i++)
{
   for(j=0;j<apiRequestusercnt;j++)
   {
      //run api HTTP request
   }
}
 ```
Please help me how can i do this in Jmeter?

1 个答案:

答案 0 :(得分:0)

我认为您不需要在那里使用2个线程组,只需将登录并获取令牌的逻辑放在Once Only Controller

enter image description here

因此,假设您在Thread Group中设置了5个线程和5个循环,您将获得1个授权请求,然后每个用户5个API请求

另外请注意,starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language用于脚本编写主要是因为Groovy has much better performance comparing to Beanshell

相关问题