Restful接口_locust性能测试_4

运行模式

1、无web界面模式
运行模式
no-web 运行
前面是通过登录 web 来运行测试的,其实也可以非web状态来运行,如cmd命令来运行。如果需要非Web形式运行,则需使用 
--no-web 参数,并会用到如下几个参数。
-c, --clients :指定并发用户数;
-r, --hatch-rate :指定并发加压速率,默认值位 1。
-t, --run-time :设置运行时间。如(300s,20m, 3h, 1h30m 等);

运行命令如下:
C:\Users\admin>locust -f E:\django_restful\api\locust\restful_api_params.py --no-web -c 10 -r 2 -t 15s

2、分布式运行
分布式运行
上面我们都是单台机器来执行性能测试,但是当单台机器不够模拟足够多的用户时,Locust 支持运行在多台机器中进行压力测试。分布式运行一般是一台 master 多台 slave 如下图所示:
首先定义一台 master
C:\Users\admin>locust -f E:\django_restful\api\locust\restful_api_params.py --master

再定义slave(多台,开多个cmd命令)
C:\Users\admin>locust -f E:\django_restful\api\locust\restful_api_params.py --slave
如果 slave 与 master 不在同一台机器上,还需要通过 --master-host 参数再指定 master 的 IP 地址:
C:\Users\admin>locust -f E:\django_restful\api\locust\restful_api_params.py --slave --master-host <master_IP>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容