1)安装locust 命令行执行
2)准备代码 task.py - from locust import HttpLocust, TaskSet, task
-
- class WebsiteTasks(TaskSet):
- def on_start(self):
- self.client.post("/login", {
- "username": "yourname",
- "password": "yourpass"
- })
-
- @task
- def index(self):
- self.client.get("/")
-
- @task
- def about(self):
- self.client.get("/account/new")
-
- class WebsiteUser(HttpLocust):
- task_set = WebsiteTasks
- min_wait = 5000
- max_wait = 15000
复制代码
3)开启服务 命令行执行 - locust -f task.py -H http://127.0.0.1:80
复制代码
4)打开管理界面 http://127.0.0.1:8089/ 并配置,模拟人数 每秒请求数
结果如下
|