导语:
本文主要介绍了关于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"})
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ python编码和解码有什么区别?11/11
- ♥ python超函数的调用方法12/01
- ♥ python一般用什么IDE09/25
- ♥ 如何退出python多线程编程09/28
- ♥ python自定义如何捕获错误09/08
- ♥ python元组有什么优点12/02
内容反馈