An open source load testing tool.
Define user behaviour with Python code, and swarm your system with millions of simultaneous users
一个开源的负载测试工具。 使用Python代码定义用户行为,并使用数百万并发用户群访问您的系统。
这个自然不是我说的,人家官网超赞的:https://www.locust.io/ 完全就是不需要参考别人
pip install locustio
自己简单写的例子,主要想下次还可以用
from locust import HttpLocust, TaskSet, task
class LeadsCloud(TaskSet):
'''继承TaskSet类,用于描述用户行为'''
# 当模拟用户开始执行TaskSet类时,on_start函数就会被调用。
def on_start(self):
self.client.post("http://127.0.0.1:5000/login/login", {
'type': '0',
'phone': '15842961234',
'code': '1111'
})
@task()
def test_print(self):
print("hello world")
@task()
def getShoppingList(self):
self.client.post("http://127.0.0.1:5000/test/getList")
class WebsiteUser(HttpLocust):
task_set = LeadsCloud # 指向一个定义的用户行为类
host = 'http://127.0.0.1' # 指定一个访问ip
min_wait = 3000 # 执行事务之间用户等待时间的下限
max_wait = 6000 # 执行事务之间用户等待时间的上限
if __name__ == "__main__":
import os
os.system("locust -f locust_test.py --host=http://127.0.0.1")