diff --git a/docs/api.rst b/docs/api.rst index 36dd8f5b23..4820ceaae9 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -7,20 +7,20 @@ Locust class ============ .. autoclass:: locust.core.Locust - :members: min_wait, max_wait, task_set, weight + :members: min_wait, max_wait, wait_function, task_set, weight HttpLocust class ================ .. autoclass:: locust.core.HttpLocust - :members: min_wait, max_wait, task_set, client + :members: min_wait, max_wait, wait_function, task_set, client TaskSet class ============= .. autoclass:: locust.core.TaskSet - :members: locust, parent, min_wait, max_wait, client, tasks, interrupt, schedule_task + :members: locust, parent, min_wait, max_wait, wait_function, client, tasks, interrupt, schedule_task task decorator ============== diff --git a/examples/custom_wait_function.py b/examples/custom_wait_function.py new file mode 100644 index 0000000000..9a16727f67 --- /dev/null +++ b/examples/custom_wait_function.py @@ -0,0 +1,51 @@ +from locust import HttpLocust, TaskSet, task +import random + +def index(l): + l.client.get("/") + +def stats(l): + l.client.get("/stats/requests") + +class UserTasks(TaskSet): + # one can specify tasks like this + tasks = [index, stats] + + # but it might be convenient to use the @task decorator + @task + def page404(self): + self.client.get("/does_not_exist") + +class WebsiteUser(HttpLocust): + """ + Locust user class that does requests to the locust web server running on localhost + """ + host = "http://127.0.0.1:8089" + # Most task inter-arrival times approximate to exponential distributions + # We will model this wait time as exponentially distributed with a mean of 1 second + wait_function = lambda: random.expovariate(1)*1000 # *1000 to convert to milliseconds + task_set = UserTasks + +def strictExp(min_wait,max_wait,mu=1): + """ + Returns an exponentially distributed time strictly between two bounds. + """ + while True: + x = random.expovariate(mu) + increment = (max_wait-min_wait)/(mu*6.0) + result = min_wait + (x*increment) + if result