Locust類體現了一個用戶(或者一窩蜜蜂)。Locust將會爲每一個被模擬的用戶產下一個locust類的實例。locust類須要定義以下屬性:html
伴隨着task_set屬性,每每會聲明min_wait 和 max_wait屬性。也就是以毫秒爲單位的最小時間和最大時間,用於設置虛擬用戶執行任務的間隔時間。min_wait 和 max_wait默認爲1000,所以若是沒有聲明min_wait 和 max_wait,一個locust將會在執行完一個任務後等待1秒。web
下面的locust文件,每一個用戶執行任務的間隔是5到15秒api
from locust import Locust, TaskSet, task class MyTaskSet(TaskSet): @task def my_task(self): print "executing my_task" class MyLocust(Locust): task_set = MyTaskSet min_wait = 5000 max_wait = 15000
min_wait and max_wait屬性也能夠在TaskSet類裏被重寫google
能夠在相同的文件運行兩個locust(飛兩個蜜蜂):spa
locust -f locust_file.py WebUserLocust MobileUserLocust
若是但願其中一個locust相對其它locust有更高的執行機率,能夠在這些類裏設置權重屬性。例如:web用戶的執行機率是mobile用戶的三倍:命令行
class WebUserLocust(Locust): weight = 3 .... class MobileUserLocust(Locust): weight = 1 ....
host屬性是附加在被加載的host上的URL 前綴(i.e.「http://google.com」)。一般在locust被啓動時,會經過--host在命令行中將其聲明。若是在locust類中定義了host屬性,命令行中--host未被指定的話,就會使用locust類中定義的host屬性。code