python中Locust的安装和使用
1、执行pip命令:
$pipinstalllocust
2、使用Locust一般按照以下步骤进行:编写python用户脚本。使用locust命令执行性能测试。(可选)通过Web界面监测结果。
importtime fromlocustimportHttpUser,task,between classQuickstartUser(HttpUser): wait_time=between(1,2.5) @task defhello_world(self): self.client.get("/hello") self.client.get("/world") @task(3) defview_items(self): foritem_idinrange(10): self.client.get(f"/item?id={item_id}",name="/item") time.sleep(1) defon_start(self): self.client.post("/login",json={"username":"foo","password":"bar"})
以上就是python中Locust的安装和使用,希望对大家有所帮助。更多python学习指路:python基础教程
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。