当前位置:网站首页>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 locust
Name: locust
Version: 1.4.4
Summary: Developer friendly load testing framework
Home-page: https://locust.io/
4.快速开始
在Locust中,您可以使用Python代码定义用户行为。然后,您可以使用该locust命令和(可选)其Web界面在收集请求统计信息时生成并模拟大量这些用户。
locust_cnblogs.py
''''
Create by dell on 2021/4/13
Author :wencheng
describe :
'''
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 2.5)
@task
def bky_deom(self):
self.client.get("/")
@task(3)
def bky_demo2(self):
self.client.get("/wen-cheng")
if __name__ == '__main__':
import os
os.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)实时统计 平均响应时间/平均事务数实时统计 虚拟用户数运行
导出数据
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家的支持。
学习资源分享
最后感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走
这些资料,对于想【进阶自动化测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!凡事要趁早,特别是技术行业,一定要提升技术功底。希望对大家有所帮助…….
边栏推荐
- 开户哪家券商比较好?网上开户安全吗
- The drawing method of side-by-side diagram, multi row and multi column
- 283. 移动零-c与语言辅助数组法
- Redis03 - network configuration and heartbeat mechanism of redis
- 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
- 凭借了这份 pdf,最终拿到了阿里,字节,百度等八家大厂 offer
- 案例分享|金融业数据运营运维一体化建设
- [early knowledge of activities] list of recent activities of livevideostack
- QT—绘制其他问题
- 哈希表(Hash Tabel)
猜你喜欢
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
The use of complex numbers in number theory and geometry - Cao Zexian
Master the use of auto analyze in data warehouse
How to remove the black dot in front of the title in word document
常用的开源无代码测试工具
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
QT - plot other problems
力扣98:验证二叉搜索树
Bookmark
How to implement Devops with automatic tools
随机推荐
Deveco device tool 3.0 release brings five capability upgrades to make intelligent device development more efficient
NAACL-22 | 在基于Prompt的文本生成任务上引入迁移学习的设置
HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
智洋创新与华为签署合作协议,共同推进昇腾AI产业持续发展
传智教育|如何转行互联网高薪岗位之一的软件测试?(附软件测试学习路线图)
力扣3_383. 赎金信
GTEST from ignorance to proficient use (2) what is test fixture
# 2156. Find the substring of the given hash value - post order traversal
Is it safe to open an account in the stock of Caicai college? Can you only open an account by digging money?
PostgreSQL基本结构——表
Interview question 01.08 Zero matrix
AcWing 2022 每日一题
1807. Replace the parentheses in the string
可视化任务编排&拖拉拽 | Scaleph 基于 Apache SeaTunnel的数据集成
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
Master the use of auto analyze in data warehouse
sqlserver对数据进行加密、解密
WebGIS框架---kalrry
El tree combined with El table, tree adding and modifying operations
力扣2_1480. 一维数组的动态和