当前位置:网站首页>Locust性能测试 —— 环境搭建及使用
Locust性能测试 —— 环境搭建及使用
2022-07-04 21:39:00 【测试界的彭于晏】
1.什么是Locust?
Locust是一个易于使用,可编写脚本且可扩展的性能测试工具。您可以使用常规Python代码定义用户的行为,这使Locust可以无限扩展,并且对开发人员非常友好。
2.特征
分布式和可扩展-支持数十万用户
Locust使运行分布在多台计算机上的负载测试变得容易。它是基于事件的(使用gevent),这使得单个进程可以处理成千上万的并发用户。尽管可能还有其他工具可以在给定的硬件上每秒执行更多请求,但是每个Locust用户的低开销使其非常适合测试高并发工作负载。
基于Web的UI
Locust具有用户友好的Web界面,可实时显示测试进度。您甚至可以在测试运行时更改负载。它也可以在没有UI的情况下运行,从而使其易于用于CI / CD测试。
可以测试任何系统
即使Locust主要与网站/服务一起使用,它也可以用于测试几乎所有系统或协议。只需 为您要测试的内容编写一个客户端,或者浏览社区创建的一些客户端。
3.环境安装
官方文档
https://docs.locust.io/en/1.4.4/what-is-locust.html
安装Python 3.6或更高版本。
使用pip安装Locust。pip install locust
验证安装并显示locust版本号pip show locust(venv) E:\workspace\LocustConcurrent>pip show locustName: locustVersion: 1.4.4Summary: Developer friendly load testing frameworkHome-page: https://locust.io/
4.快速开始
在Locust中,您可以使用Python代码定义用户行为。然后,您可以使用该locust命令和(可选)其Web界面在收集请求统计信息时生成并模拟大量这些用户。
locust_cnblogs.py
''''Create by dell on 2021/4/13Author :wenchengdescribe :'''from locust import HttpUser, task, betweenclass QuickstartUser(HttpUser):wait_time = between(1, 2.5)@taskdef bky_deom(self):self.client.get("/")@task(3)def bky_demo2(self):self.client.get("/wen-cheng")if __name__ == '__main__':import osos.system('locust -f locust_cnblogs.py -H https://www.cnblogs.com')
5.启动运行locust

打开locust的web界面,浏览器访问:http://127.0.0.1:8089
设置虚拟用户数20,每秒启动5个用户,点击Start swarming 开始运行

locust的web界面分析:
Number of users to simulate是模拟用户的数量
Hatch rate (users spawned/second表示产生模拟用户的速度
Start swarming开始测试
6.分析测试结果

Type:请求类型;
Name:请求路径;
Requests:当前请求的数量;
Fails:当前请求失败的数量;
Median:中间值,单位毫秒,一般服务器响应时间低于该值,而另一半高于该值;
Average:所有请求的平均响应时间,毫秒;
Min:请求的最小的服务器响应时间,毫秒;
Max:请求的最大服务器响应时间,毫秒;
Content Size:单个请求的大小,单位字节;
Reqs/sec:每秒钟请求的个数。
界面图表展示


吞吐量/每秒响应事务数(rps)实时统计 平均响应时间/平均事务数实时统计 虚拟用户数运行
导出数据

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家的支持。
学习资源分享
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走

这些资料,对于想【进阶自动化测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….

边栏推荐
- HDU - 1078 fatmouse and cheese (memory search DP)
- Enlightenment of maker thinking in Higher Education
- bizchart+slider实现分组柱状图
- Use of class methods and class variables
- Super detailed tutorial, an introduction to istio Architecture Principle and practical application
- new IntersectionObserver 使用笔记
- 1807. Replace the parentheses in the string
- AscendEX 上线 Walken (WLKN) - 一款卓越领先的“Walk-to-Earn”游戏
- i. Mx6ull driver development | 24 - platform based driver model lights LED
- Use blocconsumer to build responsive components and monitor status at the same time
猜你喜欢

机器学习笔记 - 互信息Mutual Information

TCP协议三次握手过程

The use of complex numbers in number theory and geometry - Cao Zexian

传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)

Exclusive interview of open source summer | new committer Xie Qijun of Apache iotdb community

抖音实战~评论数量同步更新

凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer

Operation of adding material schedule in SolidWorks drawing

How to remove the black dot in front of the title in word document

做BI开发,为什么一定要熟悉行业和企业业务?
随机推荐
复数在数论、几何中的用途 - 曹则贤
迷失在Mysql的锁世界
GTEST from ignorance to proficient use (2) what is test fixture
Radio and television Wuzhou signed a cooperation agreement with Huawei to jointly promote the sustainable development of shengteng AI industry
El tree combined with El table, tree adding and modifying operations
Solve the problem of data disorder caused by slow asynchronous interface
Machine learning notes mutual information
MongoDB中的索引操作总结
CloudCompare&Open3D DBSCAN聚类(非插件式)
湘江鲲鹏加入昇腾万里伙伴计划,与华为续写合作新篇章
ApacheCN 翻译、校对、笔记整理活动进度公告 2022.7
保证接口数据安全的10种方案
TCP协议三次握手过程
HDU - 1078 fatmouse and cheese (memory search DP)
【C语言进阶篇】数组&&指针&&数组笔试题
Delphi soap WebService server-side multiple soapdatamodules implement the same interface method, interface inheritance
sqlserver对数据进行加密、解密
HDU - 2859 Phalanx(DP)
并发优化总结
PostgreSQL基本结构——表