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