使用 JMeter 测试:如何每秒运行 N 个请求
我需要测试我们的系统是否可以每秒执行 N 个请求。 从技术上讲,这是对一个 API 的 2 个请求,对另一个 API 的 2 个请求,以及对第三个 API 的 6 个请求。 但重要的是它们应该同时发生 - 所以每秒 10 个请求。 因此,在 JMeter 中我创建了三个线程组,首先定义线程数 1,启动时间 0。 第二个线程组相同,第三个线程组定义线程数 6 和启动时间 0。 但这并不能真正保证它会每秒运行它们 我该如何效仿呢?我如何查看结果——是否能够执行?
谢谢!
I need to test if our system can perform N requests per second.
Technically, it's 2 requests to one API, 2 requests to another, and 6 requests to third one.
But the important thing that they should happen simultaneously - so 10 requests per second.
So, in JMeter I've created three Thread Groups, first defines number of threads 1, and ramp-up time 0.
Second thread group is the same, and third thread group defines number of threads 6 and ramp-up time 0.
But that doesn't really guarantee it's going to run them per second
How do I emulate that? And how do I see the results -- if it was able to perform or wasn't?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用ConstantThroughputTimer。
引用以下 JMeter 帮助文件:
例如,我使用它每秒生成 40 个请求:
这就是摘要:
但我在我的网络内运行此测试。
You could use
ConstantThroughputTimer
.Quote from JMeter help files below:
For example I've used it to generate 40 requests per second:
And thats a summary:
But I run this test inside my network.
与任何网络测试一样,总是会出现问题,尤其是延迟 - 即使您每秒可以发送 6 个数据包,它们也会按顺序发送(这就是数据包的发送方式)并且可能不会在那一秒内全部命中,再加上处理时间。
通常,当性能指标具体为每秒 x 时,它是在一段时间内进行测量的。你的 API 甚至可能有一个缓冲区 - 所以从技术上讲你可以每秒发送 6 个,但每秒处理 5 个,缓冲区为 20,这意味着 20 秒的流量就可以了,因为你已经发送了 120 个,这处理需要 120/5 = 24 秒。但超过这个数就会溢出缓冲区。因此,仅仅在一秒钟内发送 6 个数据进行测试是不够的。
在线程组中,您将线程(用户)数设置为 6 是正确的。然后永远循环运行它(勾选它或将其放入 while 循环中)并添加一个监听器,例如聚合报告和结果树。您可以使用结果来检查是否发送和响应了正确的内容(假设您验证了响应),并且在汇总报告中,您可以看到每小时发生的每个活动有多少(显然是乘以 3600 秒,但是由于这种不准确性,最好运行它很长一段时间)。
现在可以运行初始负载测试,作为更准确的测试,您可以让它运行更长时间(浸泡测试),以查看是否出现任何其他问题 - 缓冲区溢出、内存泄漏或其他意外事件。
As with any network test, there's always going to be problems, especially with latency - even if you could send exactly 6 per second, they're going to be sent sequentially (that's just how packets get sent) and may not all hit in that second, plus processing time.
Generally when performance metrics specific x per second, it's measured over a period of time. Your API may even have a buffer - so you could technically send 6 per second, but process 5 per second, with a buffer of 20, meaning it'd be fine for 20 seconds of traffic, as you'd have sent 120, which would take 120/5 = 24 seconds to process. But any more than that would overflow the buffer. So to just send exactly 6 in a second to test is insufficient.
In the thread group, you're right setting number of threads (users) to 6. Then run it looping forever (tick it or put it in a while loop) and add a listener like aggregate report and results tree. The results you can use to check the right stuff is being sent and responded to (assuming you validate the responses) and in the aggregate report, you can see how many of each activity is happening per hour (obviously multiply by 3600 for seconds, but because of this inaccuracy it's best to run it for a good length of time).
The initial load test can now be run, and as a more accurate test, you can leave it running for longer (soak test) to see if any other problems surface - buffer overflows, memory leaks, or other unexpected events.
使用吞吐量调整计时器
Use the Throughput Shaping Timer
我遇到了类似的问题,以下是我找到的两个解决方案:
解决方案 1:
您可以使用步进线程组(允许在设定的时间段内设置线程数增加阶段)和恒定吞吐量计时器。
吞吐量计时器允许您设置线程每分钟可以发送的样本数(例如,如果将其设置为 1,则线程每分钟将仅发送一个请求)。此外,您可以将吞吐量计时器应用于线程组中的所有线程,或者为每个线程设置具有自己设置的计时器。
在此处阅读有关吞吐量计时器的更多信息:https://www.blazemeter。 com/blog/how-use-jmeters-throughput-constant-timer
解决方案 2:
使用“设置线程组”。您可以计算线程数和启动时间以获得所需的每秒线程数。
I had similar problem and here are two solutions I found:
Solution 1:
You can use Stepping Thread Group (allows to set thread number increase stages over set periods of time) with Constant Throughput Timer in it.
Throughput Timer allows you to set number of samples that thread can send per minute (e.g. if you set it to 1, the thread will only send one request per minute). Also, you can apply Throughput Timer to all threads in your Thread Group or have Timer for each thread with its own settings.
Read more about Throughput Timer here: https://www.blazemeter.com/blog/how-use-jmeters-throughput-constant-timer
Solution 2:
Use "SetUp Thread Group". You can calculate thread number and rump up time to get Threads per Second desired.
您可以使用安排反馈功能,并且还需要并发线程组
You can use Schedule Feedback Function and will also need Concurrency Thread Group
同样可以通过按照上面建议的 UI 配置“ConstantThroughputTimer”来完成,也可以通过右键单击“线程组”导航,然后单击“计时器”,然后选择“恒定吞吐量计时器”来添加“恒定吞吐量计时器”。
Same can Also be done by configuring "ConstantThroughputTimer" as suggested above from UI also by adding "Constant Throughput Timer" by navigating by right click on Thread Group and then click on Timer and then choose the "Constant Throughput Timer".