蝗虫:如何使蝗虫运行一段特定的时间

bin*_*thb 17 python load-testing locust

官方locustio文档讲述了如何编写无限运行的简单蝗虫任务.

无法找到如何运行持续特定时间的负载,以便测试将在指定的时间间隔后自动停止.

我不需要它从Web界面,命令行/代码选项将是伟大的.

小智 21

我最近开始自己使用蝗虫,不幸的是,蝗虫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
Run Code Online (Sandbox Code Playgroud)

因此,您可以使用以下内容开始会话:

# locust --clients=20 --hatch-rate=2 --num-request=500
Run Code Online (Sandbox Code Playgroud)

并且一旦处理了500个请求,它应该终止测试.


Izy*_*zy- 7

参加聚会的时间很晚,但是我偶然发现停止测试,这可能有所帮助。

stop_timeout = 20 
Run Code Online (Sandbox Code Playgroud)

在你的蝗虫课上。

哦,它接受的值。

  • 要添加它,您需要将 `stop_timeout=20` 放入继承自 `Locust` 或 `HttpLocust` 的负载测试类中 (2认同)

Abh*_*lvi 6

回答可能为时已晚,但将来可能对某人有所帮助。现在,使用--no-web选项运行Locust时,Locust 支持-t--run-time选项来指定持续时间。来自locust --help

-t RUN_TIME, --run-time=RUN_TIME
                        Stop after the specified amount of time, e.g. (300s,
                        20m, 3h, 1h30m, etc.). Only used together with --no-
                        web
Run Code Online (Sandbox Code Playgroud)


gra*_*hay 5

可以通过抛出StopLocust异常来停止单个greenlet("locust"),这样你就可以在Task中添加一个检查时间来检查时间

这是未记录的行为,将来可能会改变,但它在0.7.2中有效!

http://lookonmyworks.co.uk/2015/03/13/stopping-a-locust/


小智 5

蝗虫现在支持运行时参数--run-time=1h20m。我从master分支安装了蝗虫。(请参阅GitHub 问题)。我认为此功能已在0.9v中正式发布。