python中Locust的安装和使用

413次阅读
没有评论

python中Locust的安装和使用

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"})
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-07-14发表,共计576字。
新手QQ群:570568346,欢迎进群讨论 Python51学习