如何在 Gatling 中注入恒定数量的用户?

zsl*_*lim 5 performance-testing gatling

我不清楚如何在 Gatling 中控制封闭的工作负载模型。

如果我使用constantConcurrentUsers,像这样:

myScenario.inject(
    constantConcurrentUsers(40) during (2 minutes)
)
Run Code Online (Sandbox Code Playgroud)

我认为这意味着活跃用户的数量将保持不变。但相反,我得到这样的报告:

40个恒定并发用户?

用户数量不是恒定的,是我想要的数量的 3-5 倍。

不过,在控制台输出中,我可以看到某些内容是恒定的(这里有 4 个场景,每个场景都加载了 10 个恒定并发用户):

40个恒定并发用户的控制台输出

但是总负载比我预期的要多得多。

我曾尝试过节流,结果很明显。在我的理解中,节流阀使并发活动请求的数量最大化(如果请求已发送但尚未响应,则该请求处于活动状态)。我定义了一些应该通过的请求,每次完成时 Gatling 都会发送一个新请求。并且由于响应时间之间没有太大差异,因此报告如下所示:

使用节流阀发送的恒定请求数

我想做同样的事情,但这样我就可以控制模拟的长度,而不是发送的请求总数。constantConcurrentUsers似乎正是我需要的东西,但它产生了意想不到的结果。我的油门模拟在大约1分钟内做了大约3000个请求,油门为50。同时,如果我设置50个并发用户1分钟,报告中发送了7000多个请求。在油门情况下,响应时间要短得多。所以节流模拟发送请求比并发用户模拟慢得多,但不是因为请求需要更多时间。

我知道活动用户和发送的请求是不一样的,它们constantConcurrentUsers控制用户数量,而节流控制请求。但是我所有的场景都只包含一个请求,所以我不明白结果之间的区别。

所以我的问题是:

  • 当我使用时到底什么是常数constantConcurrentUsers
  • 我使用时如何计算请求数constantConcurrentUsers
  • 报告中的“活跃用户”与控制台输出中的“活跃用户”之间有什么关系?

我已经阅读了 Gatling 文档的这一部分,它真的很短,而且缺乏详细的描述。我还阅读了这篇文章,其中包含我从未在任何 Gatling 报告中看到的图表,并且没有回答我的问题。

感谢您的任何贡献。

小智 6

I have found that the Cheatsheet describes each injection step most accurately. How you inject a constant number of users should be using constantConcurrentUsers which is described in the Cheatsheet as: "Maintain a constant number of concurrent users"

\n\n

As for your other questions:

\n\n
\n
    \n
  • What exactly is constant when I use constantConcurrentUsers?
  • \n
\n
\n\n

I believe Gatling does keep the number of concurrent users constant. The reason there are spikes in the number of requests is because one user can make multiple requests in a given timespan. As soon as the current request finishes for the user, a new request is fired by the same user. In your example, you had 40 users and your number of requests looks around 80, this indicates each user was achieving 2 requests a second (mean response time around 500ms?)

\n\n
\n
    \n
  • How is the number of requests calculated when I use constantConcurrentUsers?
  • \n
\n
\n\n

As per above, your concurrent users will just keep looping the request for the duration you set and it will not fire another until the current request provides a response. If your API is quick, your number of requests per second will be higher than your number of users.

\n\n
\n
    \n
  • What is the relation between "active users" in the report and "active" in the console output?
  • \n
\n
\n\n

This is actually where I am a bit unsure :/ I set have 10 constantConcurrentUsers in my test, and console shows similar to yours, but my report shows between 10-75 active users over time\n10 个恒定并发用户

\n\n

However, this Reports page in Gatling docs sheds some light:

\n\n
\n

\xe2\x80\x9cActive users\xe2\x80\x9d is neither \xe2\x80\x9cconcurrent users\xe2\x80\x9d or \xe2\x80\x9cusers arrival rate\xe2\x80\x9d.\n It\xe2\x80\x99s a kind of mixed metric that serves for both open and closed\n workload models and that represents \xe2\x80\x9cusers who were active on the\n system under load at a given second\xe2\x80\x9d.

\n \n

It\xe2\x80\x99s computed as:

\n \n

(number of alive users at previous second)\n + (number of users that were started during this second)\n - (number of users that were terminated during previous second)

\n
\n

  • 嘿,谢谢你的回答。是的,最终我了解到constantConcurrentUsers会注入x个用户,并且每当用户完成时,立即注入一个新用户。这就是该方法生成的负载取决于响应时间的原因。 (3认同)