Python+Locust性能测试
1、设置断言监控接口请求成功和失败,一定要再请求接口的时候添加catch_response=True这个参数,locust会通过自定义情况来判断接口请求的成功与否
(比如说接口返回404,500的时候,如果不添加此块代码,locust也会自动统计为接口请求是成功的)
response=self.client.post(接口地址,json=参数,catch_response=True)
if "login_pass" in response.txt:
response .success()
else:
response .failure("Can not login!")
可以在主函数中通过os.system("locust -f ability_locust.py --host=http://www.baidu.com") 来本地启动和调试locust
locust参考文档:https://cloud.tencent.com/developer/article/1594240
locust官方文档:https://docs.locust.io/en/stable/quickstart.html
locust代码demo参考文档:http://www.

本文介绍了如何使用Python的Locust库进行性能测试,包括设置断言监控接口请求、处理后端返回的JSON数据、多用户随机参数化、利用Psutil监控系统资源以及性能指标分析,如响应时间、吞吐量、TPS和资源利用率。
最低0.47元/天 解锁文章
992

被折叠的 条评论
为什么被折叠?



