官方locustio documentation讲述如何编写无限期运行的简单 locust 任务。
无法找出如何运行持续特定时间的负载,以便测试将在指定的时间间隔后自动停止。
我不需要从 web 界面使用它,命令行/代码选项会很棒。
最佳答案
这个答案已经过时了。 Locust 现在有一个 -t/--run-time 参数用于指定运行时间。见 https://docs.locust.io/en/stable/running-without-web-ui.html?highlight=run-time#setting-a-time-limit-for-the-test
我最近自己开始使用 locust,不幸的是 locust 0.7.1 没有提供基于时间长度终止测试的方法。
但是,它确实提供了一种根据已发出的请求数终止测试的方法。如果您使用 CLI 界面运行 locust,您可以指定它在处理指定数量的请求后停止执行。从 locust --help
输出:
-n NUM_REQUESTS, --num-request=NUM_REQUESTS
Number of requests to perform. Only used together with --no-web
因此,您可以使用以下内容开始 session :
# locust --clients=20 --hatch-rate=2 --num-request=500
一旦处理了 500 个请求,它应该终止测试。
关于python - 蝗虫 : How to make locust run for a specific amount of time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392451/