知行编程网知行编程网  2023-01-11 13:00 知行编程网 隐藏边栏  6 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python中Locust的安装和使用的相关知识,希望可以帮到处于编程学习途中的小伙伴

Locust在python中的安装与使用


1、

执行pip命令:

$ pip install locust


2、使用Locust一般按照以下步骤进行:

编写Python用户脚本。使用locust命令执行性能测试。(可选)通过Web界面监测结果。

import time
from locust import HttpUser, task, between
 
class QuickstartUser(HttpUser):
    wait_time = between(1, 2.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("/login", json={"username":"foo", "password":"bar"})


本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享