locustio/locust — pull request #43 by heyman (2012-11-16 00:25:18+00:00)
Title: Change Locust/SubLocust API

I've been thinking about how we can improve the Locust API when it comes to the task scheduling/Locust/SubLocust parts. I think the current API is really good for realistically simulating real users with few lines of code. However, I think that the naming is a bit confusing, and that it can be an obstacle for new users to understand Locust.

This issue is very much related to #16

Here is an idea for a slightly changed API which I think could make it much clearer:

```python
from locust import Locust, TaskSet, task

class WebsiteUser(Locust):
host = "http://127.0.0.1"
min_wait = 3000
max_wait = 90000
task_set = IndexPage

class IndexPage(TaskSet):
@task
def index(self)
self.client.get("/")

@task
def some_other_task(self):
pass
```

It makes for a *slightly* more complicated "Hello World" locustfile, but at the same time it separates the purpose of Locust from the purpose of TaskSet.

A few points about the above idea:

* TaskSets can be nested, just like SubLocusts currently can
* **client** is created on the Locust class but is also available as an attribute in the TaskSet instances
* All TaskSets (no matter how long down in the hierarchy) can access the Locust instance through a **locust** attribute
* **min_wait** and **max_wait** can be overridden in a TaskSet

What do you think? This is just an idea, and it would be great with feedback :)!