locust 性能测试工具使用资料
2023-03-07 09:44:10 时间
认识和安装 locust
- https://www.cnblogs.com/imyalost/p/9758189.html
- https://docs.locust.io/en/stable/installation.html
- https://debugtalk.com/post/head-first-locust-user-guide/
# windows 10
pip3 install -i https://pypi.douban.com/simple/ locustio==0.14.6
启动参数介绍
- https://docs.locust.io/en/stable/configuration.html(官方英文)
- https://www.jianshu.com/p/1a57f80fd480(部分中文翻译)
举个例子
# car_city.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: yinzhuoqun
@site: http://xieboke.net/
@email: yin@zhuoqun.info
@time: 2020/9/16 18:15
"""
import os
import requests
from locust import HttpLocust, TaskSet, task
requests.packages.urllib3.disable_warnings()
class WXLogin(TaskSet):
# @task 装饰该方法表示为用户行为,括号里面参数表示该行为的执行权重:数值越大,执行频率越高,不设置默认是1;
@task(1)
def garage_upgrade(self):
header = {
"User-Agent": "xxxx/1.0.0 (Linux; U; Android 10; zh-cn) (default; 1000000)",
"Host": "xxx",
"token": "xxx"
}
json_data = {
"number": 1,
"spaceId": 1
}
# post 请求使用 client.post,get 请求使用 client.get
req = self.client.post("/garage/upgrade", headers=header, json=json_data, verify=False)
if req.status_code == 200:
print("success")
else:
print("failed")
class CarCityUser(HttpLocust):
task_set = WXLogin # 指向定义了用户行为的类
host = "http://xxx.com" # 被测的 Host
min_wait = 3000 # 单位为毫秒,模拟负载的任务之间执行时的最小等待时间
max_wait = 6000 # 单位为毫秒,模拟负载的任务之间执行时的最大等待时间
脚本增强
https://debugtalk.com/post/head-first-locust-advanced-script/
源码分析
- https://www.missshi.cn/api/view/blog/59a6b53fe519f50d04000103
- https://blog.csdn.net/biheyu/category_1882447.html(备用地址)
分布式启动
先启动 master (主机):访问 http://localhost:8089/ 可查状态
locust -f car_city.py --master
再启动 slave (从机,--master-host 后面写主机 IP)
locust -f car_city.py --slave --master-host=192.168.89.126
启动从机后主机控制台会有连接上的日志
E:\yinzhuoqun\locust_test>locust -f car_city.py --master
[2020-09-17 17:49:04,720] DESKTOP-9K42C1Q/INFO/locust.main: Starting web monitor at http://*:8089
[2020-09-17 17:49:04,721] DESKTOP-9K42C1Q/INFO/locust.main: Starting Locust 0.14.6
[2020-09-17 17:54:52,244] DESKTOP-9K42C1Q/INFO/locust.runners: Client 'DESKTOP-9K42C1Q_bc7e6bdd22c84c48bb910f5be41d80a6' reported as ready. Currently 1 clients ready to swarm.
[2020-09-17 17:55:31,724] DESKTOP-9K42C1Q/INFO/locust.runners: Client 'DESKTOP-9K42C1Q_bc7e6bdd22c84c48bb910f5be41d80a6' quit. Currently 0 clients connected.
[2020-09-17 17:55:49,913] DESKTOP-9K42C1Q/INFO/locust.runners: Client 'DESKTOP-9K42C1Q_52383b135c4f4f9ea39cdaf3eceb0d83' reported as ready. Currently 1 clients ready to swarm.
[2020-09-17 18:05:31,840] DESKTOP-9K42C1Q/INFO/locust.runners: Sending hatch jobs of 2 locusts and 2.00 hatch rate to 1 ready clients
[2020-09-17 18:05:49,141] DESKTOP-9K42C1Q/INFO/locust.runners: Removing DESKTOP-9K42C1Q_52383b135c4f4f9ea39cdaf3eceb0d83 client from running clients
[2020-09-17 18:05:49,142] DESKTOP-9K42C1Q/INFO/locust.runners: Client 'DESKTOP-9K42C1Q_52383b135c4f4f9ea39cdaf3eceb0d83' reported as ready. Currently 1 clients ready to swarm.
[2020-09-17 18:13:44,857] DESKTOP-9K42C1Q/INFO/locust.runners: Client 'XG7TARM8695SQQL_73f8971e70ff47bab372054da9b1db8b' reported as ready. Currently 2 clients ready to swarm.
遇到的问题
在win10,从机启动后无法连接到主机(主机和从机不在同一台电脑),原因是主机的端口 5557 和 5558 没有加入到 入站规则,即该端口没开放别的机器无法访问(入站规则设置方法)
运行效果图
相关文章
- AppSync调试方法
- Amazon Managed Grafana 现已全面推出,并具有许多新功能
- AWS CloudFormation 的新功能 – 从故障点快速重试堆栈操作
- 使用更具体的 Amazon VPC 路由检查子网到子网的流量
- Amazon Textract 更新:8 个亚马逊云科技区域的价格降幅达 32%,异步任务处理时间缩短近 50%
- Announcing the latest AWS Heroes – August 2021
- 云原生编排数据分析管道初探
- 使用托管节点组结合启动模板简化EKS升级与运维
- 如何将您的自定义容器镜像导入Amazon SageMaker Studio notebooks
- 如何注册成为亚马逊云科技 Marketplace海外区卖家
- 如何使用数据网格创建现代包装消费品 (CPG)行业数据架构
- 预处理日志以便在 Amazon ES 中进行异常检测
- java deque_java 集合框架(十五)Deque
- 基于AI技术的智能剪辑方案
- 使用 AWS Backup Audit Manager 监控、评估和证明备份合规性
- Amazon EC2!15 岁生日快乐!
- java lamda_Java 8中,lamda函数编程
- 关于Amazon EKS中Service和Ingress深入分析和研究
- 游戏公司多账号管理(一)
- 新增 — 由最新一代英特尔至强可扩展处理器提供支持的 Amazon EC2 M6i 实例