Locust 命令行运行测试
在没有 Web UI 界面的情况下运行 Locust
您可以在没有 Web UI 的情况下运行 Locust, 好处就是更节省客户端资源。
例如,如果您希望以某种自动化流程(例如 CI 服务器)运行 Locust,请将该 --no-web
标志与 -c
和 -r
一起使用:
$ locust -f locust_files/my_locust_file.py --no-web -c 1000 -r 100
--no-web
表示不使用 Web 界面运行测试。-c
设置虚拟用户数。-r
设置每秒启动虚拟用户数。-t
设置设置运行时间。
> locust -f load_test.py --host=https://www.baidu.com --no-web -c 10 -r 2 -t 1m
[2017-10-30 22:17:30,292] DESKTOP-SMGQBBM/INFO/locust.main: Run time limit set to 60 seconds
[2017-10-30 22:17:30,302] DESKTOP-SMGQBBM/INFO/locust.main: Starting Locust 0.8
[2017-10-30 22:17:30,302] DESKTOP-SMGQBBM/INFO/locust.runners: Hatching and swarming 10 clients at the rate 2 clients/s...
Name # reqs # fails Avg Min Max | Median req/s
....
[2017-10-30 22:18:30,301] DESKTOP-SMGQBBM/INFO/locust.main: Time limit reached. Stopping Locust.
[2017-10-30 22:18:30,302] DESKTOP-SMGQBBM/INFO/locust.main: Shutting down (exit code 0), bye.
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 117 0(0.00%) 31 17 96 | 28 2.10
--------------------------------------------------------------------------------------------------------------------------------------------
Total 117 0(0.00%) 2.10
Percentage of the requests completed within given times
Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 100%
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 117 28 30 36 37 49 62 69 72 96
--------------------------------------------------------------------------------------------------------------------------------------------
Total 117 28 30 36 37 49 62 69 72 96
为测试设置时间限制
注意
这是 v0.9 中的新功能。 对于 0.8,使用
-n
指定请求数
如果要指定测试的运行时间,可以使用--run-time
或-t
进行操作:
$ locust -f --no-web -c 1000 -r 100 --run-time 1h30m
一旦时间到,Locust 将关闭。
在没有 Web UI 的情况下运行 Locust 分布式
如果要运行不带 Web UI 的 Locust 分布式,则应在启动主节点时指定该选项,以指定 --expect-slaves
预期要连接的从节点的数量。
然后它将等待直到连接了许多从属节点,然后再开始测试。