• 技术文章 >Python技术 >Python基础教程

    python中Locust的安装和使用

    小妮浅浅小妮浅浅2021-08-03 10:08:29原创2752

    1、执行pip命令:

    1

    $ pip install locust

    2、使用Locust一般按照以下步骤进行:编写Python用户脚本。使用locust命令执行性能测试。(可选)通过Web界面监测结果。

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

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

    以上就是python中Locust的安装和使用,希望对大家有所帮助。更多Python学习指路:python基础教程

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

    专题推荐:python locust
    上一篇:python中的Locust是什么 下一篇:python中Pycharm如何调试视图

    相关文章推荐

    • python中__init__ 和__new__的对比• python中__call__的触发执行• python中__enter__和__exit__的应用场景• python中类对象及类属性的介绍• python类实例化如何实现• python实例属性的查找顺序• python保护变量是什么• python私有方法的使用注意• python析构函数如何使用• python协程和线程的差异• python库如何实现对象的转换• python中marshmallow库如何使用• python dump方法的序列化

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网