当前位置:网站首页>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)实时统计 平均响应时间/平均事务数实时统计 虚拟用户数运行
导出数据

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

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

边栏推荐
- What is the stock account opening process? Is it safe to use flush mobile stock trading software?
- 淘宝商品评价api接口(item_review-获得淘宝商品评论API接口),天猫商品评论API接口
- GTEST from ignorance to proficiency (3) what are test suite and test case
- 【Acwing】第58场周赛 题解
- 力扣_回文数
- Keep on fighting! The city chain technology digital summit was grandly held in Chongqing
- 并列图的画法,多排多列
- sqlserver对数据进行加密、解密
- 凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
- A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
猜你喜欢

Application practice | Shuhai supply chain construction of data center based on Apache Doris

Xiangjiang Kunpeng joined the shengteng Wanli partnership program and continued to write a new chapter of cooperation with Huawei
![[early knowledge of activities] list of recent activities of livevideostack](/img/14/d2cdae45a18a5bba7ee1ffab903af2.jpg)
[early knowledge of activities] list of recent activities of livevideostack

玩转gRPC—深入概念与原理

i. Mx6ull driver development | 24 - platform based driver model lights LED

What is business intelligence (BI), just look at this article is enough

广电五舟与华为签署合作协议,共同推进昇腾AI产业持续发展

PMO:比较25种分子优化方法的样本效率

bizchart+slider实现分组柱状图

MongoDB聚合操作总结
随机推荐
一文掌握数仓中auto analyze的使用
How to use concurrentlinkedqueue as a cache queue
做BI开发,为什么一定要熟悉行业和企业业务?
WebGIS framework -- kalrry
并发优化总结
能源势动:电力行业的碳中和该如何实现?
抖音实战~评论数量同步更新
从RepVgg到MobileOne,含mobileone的代码
Solana链上应用Crema因黑客攻击停运
The use of complex numbers in number theory and geometry - Cao Zexian
TCP shakes hands three times and waves four times. Do you really understand?
赋能数字经济 福昕软件出席金砖国家可持续发展高层论坛
el-tree结合el-table,树形添加修改操作
Enabling digital economy Fuxin software attends the BRICs high level Forum on Sustainable Development
Bookmark
[early knowledge of activities] list of recent activities of livevideostack
Redis03 - network configuration and heartbeat mechanism of redis
股票开户流程是什么?使用同花顺手机炒股软件安全吗?
Open3D 曲面法向量计算
面试题 01.01. 判定字符是否唯一