背景
Python3.6 性能測試框架Locust的搭建與使用
基礎
python版本:python3.6
開發工具:pycharm
Locust的安裝與配置
點擊“File”→“setting”
點擊“setting”,進入設置窗口,選擇“Project Interpreter”
點擊“+”
輸入需要“Locust”,點擊“Install Package”
安裝完成即可使用。
安裝完Locust工具后,只需要編寫一個簡單Python文件即可對系統進行負載測試。下面舉個例子:
1 from locust import Locust, TaskSet, task 2 3 class UserBehavior(TaskSet): 4 @task 5 def job(self): 6 pass 7 8 class User(Locust): 9 task_set = UserBehavior 10 min_wait = 1000 11 max_wait = 3000
然后在終端輸入:
1 mars@mars-Ideapad-V460:~/test$ locust 2 [2015-09-12 10:46:36,876] mars-Ideapad-V460/INFO/locust.main: Starting web monitor at *:8089 3 [2015-09-12 10:46:36,919] mars-Ideapad-V460/INFO/locust.main: Starting Locust 0.7.3
然后在瀏覽器中訪問localhost:8089,彈出如下頁面:
第一行Number of users to simulate
是模擬用戶的數量,第二行Hatch rate (users spawned/second
表示產生模擬用戶的速度,所有用戶產生完后開始測試統計,填寫完成后點擊“Start swarming”即可開始測試: