I'm new to locust and I'm trying to write load tests. I was wondering what is the difference between defining the tasks I want to do as callable functions rather then defining them as locust TaskSet classes. for example:
class MyTaskSet(TaskSet):
@task(2)
def index(self):
self.client.get("/")
@task(1)
def about(self):
self.client.get("/about/")
class MyLocust(HttpLocust):
task_set = MyTaskSet
or:
class about(TaskSet)
@task
def about(self):
self.client.get("/about/")
self.interrupter()
class index(TaskSet)
@task
def index(self)
self.client.get("/")
self.interrupter()
class MyTaskSet(TaskSet)
tasks = {index:2 , about: 1}
class MyLocust(HttpLocust):
task_set = MyTaskSet
what is the difference between the 2 above? thanks
TL;DR
There's a huge difference between the two in terms of load distribution.
Detailed explanation
Imagine the following setup, where one task is much slower than the other:
Below is the same setup with nested TaskSets:
When you run both scripts, you will notice that for the first setup, the load is distributed roughly as you weigh your tasks. 1/3 of the HTTP calls goes to the slow_check task and 2/3 to the fast_check task.
However, in the second setup, way more HTTP calls go to the fast_check. It looks as if a Locust (= a user) is assigned to a TaskSet, according to the 1/3-2/3 weight, but as the Locust finishes much faster, it can schedule a next task from the Fast TaskSet much faster as well.
I'm not sure if this is a bug or a feature, as it isn't mentioned specifically in the documentation.