步骤:

1)安装locustio

pip install locustio

2) 使用locust写脚本

文件名:test_download.py

 1 from locust import HttpLocust,TaskSet,task
 2 
 3 """
 4 创建后台管理站点压测类,需要继承TaskSet
 5 可以添加多个测试任务
 6 """
 7 class AdminLoadTest(TaskSet):
 8 
 9     # 用户执行task前调用
10     def on_start(self):
11         pass
12 
13     # 用户执行task后调用
14     def on_stop(self):
15         pass
16 
17     @task
18     def download(self):
19         # 头部
20         header = {"key":"value"}
21         # 参数
22         data = {"key":"value"}
23         self.client.get('/xxx/xxx',data=data,headers=header)
24 
25 class RunLoadTests(HttpLocust):
26     """
27     创建运行压测类
28     """
29     task_set = AdminLoadTest
30     min_wait = 1000
31     max_wait = 50000
32 
33 
34 if __name__ == "__main__":
35     import os
36     os.system("locust -f test_download.py --host=http://xx.xx.xx.xx:xxxx")
View Code

相关文章: