当前位置:网站首页>性能测试---locust的on_start 和 on_stop 方法
性能测试---locust的on_start 和 on_stop 方法
2022-06-21 16:08:00 【晚风吹儿】
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
用户(TaskSets)可以声明一个on_start方法或 on_stop方法。 on_start开始运行时调用它的方法, on_stop停止运行时调用它的方法。对于TaskSet on_start方法模拟用户开始执行时调用,TaskSet on_stop时模拟用户停止执行时调用
一、 on_start
解析:
每次在开始任务时,先执行on_start方法,只执行一次
再执行具体的任务
import time
from locust import HttpUser, task, between
class StartUser(HttpUser):
wait_time = between(1, 5)
@task
def hello_world(self):
self.client.get("/hello")
self.client.get("/world")
@task(3)
def view_items(self):
for item_id in range(10):
self.client.get(f"/item?id={
item_id}", name="/item")
time.sleep(1)
def on_start(self):
self.client.post("/api/v1/login",{
"username": "admin","password": "admin123"})
def on_stop(self):
time.sleep(5)
class WebsiteUser(HttpUser):
tasks = [StartUser]
host = "http://192.168.44.5:4444"
二、 on_stop
解析:
每次在开始任务时,先执行on_start方法,只执行一次
再执行具体的任务
执行完任务后去执行on_stop
import time
from locust import HttpUser, task, between
class StartUser(HttpUser):
wait_time = between(1, 5)
@task
def hello_world(self):
self.client.get("/hello")
self.client.get("/world")
@task(3)
def view_items(self):
for item_id in range(10):
self.client.get(f"/item?id={
item_id}", name="/item")
time.sleep(1)
def on_start(self):
self.client.post("/api/v1/login",{
"username": "admin","password": "admin123"})
def on_stop(self):
time.sleep(5)
class WebsiteUser(HttpUser):
tasks = [StartUser]
host = "http://192.168.44.5:4444"
三、运行规则
测试开始后,每个虚拟用户(Locust实例)的运行逻辑都会遵循如下规律:
先执行WebsiteTasks中的on_start(只执行一次),作为初始化;
从WebsiteTasks中随机挑选(如果定义了任务间的权重关系,那么就是按照权重关系随机挑选)一个任务执行;
根据Locust类中min_wait和max_wait定义的间隔时间范围(如果TaskSet类中也定义了min_wait或者max_wait,以TaskSet中的优先),在时间范围中随机取一个值,休眠等待;
重复2~3步骤,直至测试任务终止
边栏推荐
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- Chapter V operation bit and bit string
- 一招教你通过焱融 SaaS 数据服务平台+ELK 让日志帮你做决策
- 算法--按奇偶性交换后的最大数字(Kotlin)
- JetPack compose 状态提升(二)
- Google play 应用签名密钥证书,上传签名证书区别
- module.exports指向问题
- Kubernetes + Yanrong SaaS data service platform, personalized demand support has never been lost
- BFS and DFS
- 焱融科技 YRCloudFile 与安腾普完成兼容认证,共创存储新蓝图
猜你喜欢

Are the two flame retardant standards of European furniture en 597-1 and en 597-2 the same?

Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
![[MySQL learning notes 19] multi table query](/img/e6/4cfb8772e14bc82c4fdc9ad313e58a.png)
[MySQL learning notes 19] multi table query

硅橡胶玻纤管EN45545防火试验的难易程度

加密大崩盘,Web3游戏到底还有没有未来?5篇论文深度探讨

module. Exports points to problems

Integrated base scheme presentation

BM19 寻找峰值

Google play 应用签名密钥证书,上传签名证书区别

#Vscode工具#
随机推荐
list的模拟实现
How to connect the Internet - FTTH
Android kotlin 类委托 by,by lazy关键
Is it safe and reliable to open futures accounts on koufu.com?
BM22 比较版本号
Application architecture principles
Nacos注册中心-----从0开始搭建和使用
Software test architecture learning and construction (14) - overview of software test and development model of test foundation
fs. Readfile() and fs writeFile()
Create a server with node
加密大崩盘,Web3游戏到底还有没有未来?5篇论文深度探讨
ViT杀疯了,10+视觉Transformer模型详解
Yrcloudfile of Yanrong technology has completed the compatibility certification with ANTP to jointly create a new blueprint for storage
Android kotlin class delegation by, by lazy key
类、接口、函数
Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"
PTA l3-031 thousand hand Guanyin (30 points)
My gadget - card learning app is complete
拉格朗日插值
Algorithm -- maximum number after parity exchange (kotlin)