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请求后面也能够追加参数。python
物理环境安装locust以后,执行locust -f XXX.py ,路径要正确。执行成功会打印:web
[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.浏览器
填写模拟用户数和用户增加数,点下按钮就开始了。测试
能够暂停/继续。各类参数,最后一列就是每秒的请求数。code