问题描述
官方 locustio文档介绍了如何编写可无限期运行的简单蝗虫任务.
official locustio documentation tells about how to write simple locust tasks which run indefinitely.
无法确定如何运行持续特定时间的负载,因此测试将在指定的时间间隔后自动停止.
Couldn't find out how to run load which lasts for a specific amount of time, so that the test will automatically stop after the specified interval.
我不需要Web界面中的命令,命令行/代码选项将非常有用.
I dont need it from the web interface, command line/code option will be just great.
推荐答案
我最近开始自己使用蝗虫,不幸的是,蝗虫0.7.1并没有提供基于时间长度终止测试的方法.
I recently started using locust myself and unfortunately locust 0.7.1 does not provide a way to terminate a test based on a length of time.
但是,它确实提供了一种基于已发出请求的数量终止测试的方法.如果使用CLI界面运行蝗虫,则可以指定它在处理了指定数量的请求后停止执行.从locust --help
输出:
It does however provide a way to terminate the test based on the number of requests that have been issued. If you run locust using the CLI interface you can specify that it stop execution after a specified number of requests have been handled. From the locust --help
output:
-n NUM_REQUESTS, --num-request=NUM_REQUESTS
Number of requests to perform. Only used together with --no-web
因此,您可以按照以下内容开始会话:
So, you can start a session with something along the lines of:
# locust --clients=20 --hatch-rate=2 --num-request=500
一旦处理了500个请求,就应终止测试.
and once 500 requests have been handled it should terminate the test.
这篇关于蝗虫:如何使蝗虫在特定时间内运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!