1. 程式人生 > 其它 >效能測試——Locust

效能測試——Locust

1、環境

python 3.6.8

2、安裝

pip install locust 2.4.3

3、demo如下

yaCe.py

 1 from locust import HttpUser,task,between
 2 
 3 class websitUser(HttpUser):
 4     wait_time = between(1, 3)
 5     header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
"} 6 7 @task(1) 8 def baidu(self): 9 url = 'https://www.cnblogs.com/huahuage/p/12917114.html' 10 req = self.client.get(url, headers=self.header, verify=False) 11 if req.status_code == 200: 12 print("success") 13 else: 14 print("fails") 15 16
@task(2) 17 def daTong_gov(self): 18 url = "http://39.106.18.147/dtwsbm/webRegister/index.aspx?examsort=32" 19 req = self.client.get(url,headers=self.header,verify=False) 20 if req.status_code == 200: 21 print("gov_success") 22 else: 23 print("
gov_fails") 24 25 26 if __name__=="__main__": 27 import os 28 # os.system("locust -f yaCe.py --host=https://www.cnblogs.com") 29 os.system("locust -f yaCe.py")

4、他山之石

4、1 maste-slaver 配置:
在 master 模式下啟動 Locust:
locust -f my_loucstfile.py --master
在每個 slave 中執行(192.168.0.14 替換為你 msater 的IP):
locust -f my_locustfile.py --slave --master-host=192.168.0.14

4、2 結果報告指標解讀:
https://www.cnblogs.com/lizitestdev/p/14352404.html