当前位置:网站首页>Performance test ---locust's on_ Start and on_ Stop method
Performance test ---locust's on_ Start and on_ Stop method
2022-06-21 17:43:00 【The evening wind blows】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
List of articles
Preface
user (TaskSets) Can declare a on_start Method or on_stop Method . on_start Call its method when it starts running , on_stop The method that calls it when it stops running . about TaskSet on_start Method simulates that the user starts executing when ,TaskSet on_stop Is called when the user stops execution
One 、 on_start
analysis :
Every time you start a task , Execute first on_start Method , Only once
Then carry out specific tasks
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"
Two 、 on_stop
analysis :
Every time you start a task , Execute first on_start Method , Only once
Then carry out specific tasks
Go after the task 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"
3、 ... and 、 Operation rules
Once the test starts , Each virtual user (Locust example ) The operation logic of will follow the following rules :
Execute first WebsiteTasks Medium on_start( Only once ), As initialization ;
from WebsiteTasks Middle random selection ( If you define the weight relationship between tasks , Then it is randomly selected according to the weight relationship ) A task execution ;
according to Locust Class min_wait and max_wait The interval range defined ( If TaskSet It's also defined in the class min_wait perhaps max_wait, With TaskSet Priority in the world ), Pick a random value in the time range , Sleep and wait ;
repeat 2~3 step , Until the test task terminates
边栏推荐
- 加速雲原生應用落地,焱融 YRCloudFile 與天翼雲完成兼容性認證
- Google play 应用签名密钥证书,上传签名证书区别
- node服务器 res.end()中写中文,客户端中乱码问题的解决方法
- 3DE 运动轮廓数据修改
- Kotlin DSL构建
- One trick: let logs help you make decisions through Yanrong SaaS data service platform +elk
- How to adjust 3DE 3D model view if you can't see it
- Jetpack compose status promotion (II)
- Common setting modes
- BM19 寻找峰值
猜你喜欢

Pingcap was selected as the "voice of customers" of Gartner cloud database in 2022, and won the highest score of "outstanding performer"

【蓝桥杯省赛真题35】Scratch水面倒影 少儿编程scratch编程蓝桥杯省赛真题讲解

Jetpack compose phase

Volcano engine + Yanrong yrcloudfile, driving new growth of data storage

窗帘做EN 1101易燃性测试过程是怎么样的?

Bm95 points candy problem

Xticks function in MATLAB

众安保险联合阿里健康、慧医天下 探索互联网慢病管理新模式

PTA l3-031 thousand hand Guanyin (30 points)

MySQL 1055 error -this is incompatible with SQL_ mode=only_ full_ group_ By solution
随机推荐
path. join() 、path. Basename() and path extname()
The node server res.end() writes Chinese, and the solution to the problem of garbled code in the client
Bm22 compare version number
算法--按奇偶性交换后的最大数字(Kotlin)
透过华为军团看科技之变(四):互动媒体(音乐)
Clickhouse learning notes 2: basic use tutorial
3DE 运动轮廓数据修改
Kotlin DSL构建
BFS与DFS
Why is rediscluster designed with 16384 slots?
How many items should the indoor intumescent fire retardant coating meet according to BS 476-21 fire resistance standard?
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
3DE motion contour data modification
IEC62133与EN62133有何区别?主要测试哪些项目?
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
Jetpack compose status promotion (II)
Jetpack compose management status (I)
Android kotlin泛型知识点梳理
PTA L3-032 关于深度优先搜索和逆序对的题应该不会很难吧这件事 (30 分)
Convert longitude and latitude to distance