python培训之Locust的安装和使用

发布时间:2023-02-24 09:39:00 人气:30 作者:多测师

  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)

python培训之Locust的安装和使用

  @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"})

  以上就是python中Locust的安装和使用,希望对大家有所帮助。更多Python学习指路:请关注多测师。https://www.e70w.com/xwzx/




返回列表
在线客服
联系方式

热线电话

17727591462

上班时间

周一到周五

二维码
线