首页 > 应用开发 > Python > python:性能测试-locust
既然是测试开发,就肯定要写代码才行啊。loadrunner,robot framework都是写配置文件啊。
物理环境安装locust,pip3 install locust。
开发的时候如果使用虚拟环境,就在虚拟环境下安装locust。
官方的demo,这里把登陆和登出给改成打印了,其实就是压力测试执行之前和之后的步骤。
from locust import HttpLocust, TaskSet def login(l):
print("before") def logout(l):
print("after") def index(l):
l.client.get("/") class UserBehavior(TaskSet):
tasks = {index: 2} def on_start(self):
login(self) def on_stop(self):
logout(self) class WebsiteUser(HttpLocust):
host = "http://localhost:8080"
task_set = UserBehavior
min_wait = 5000
看个简介
一个简单的访问 localhost 8080端口的get请求,get请求后面也可以追加参数。
物理环境安装locust之后,执行locust -f XXX.py ,路径要正确。执行成功会打印:
[2018-12-05 23:06:51,961] DESKTOP-DOS0JSA/INFO/locust.main: Starting web monitor at *:8089 [2018-12-05 23:06:51,961] DESKTOP-DOS0JSA/INFO/locust.main: Starting Locust 0.9.0
打开浏览器访问, http://localhost:8089 .
填写模拟用户数和用户增长数,点下按钮就开始了。
可以暂停/继续。各种参数,最后一列就是每秒的请求数。
图文来源于网络:侵删
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69912078/viewspace-2637918/ ,如需转载,请注明出处,否则将追究法律责任。