summaryrefslogtreecommitdiff
path: root/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py
diff options
context:
space:
mode:
authorVinícius Zavam <egypcio@FreeBSD.org>2019-01-20 12:54:30 +0000
committerVinícius Zavam <egypcio@FreeBSD.org>2019-01-20 12:54:30 +0000
commitf20baa6ebd75e5a55ec1d3755ef4c61b83fd5924 (patch)
treecf48db9b35cfc5a7de462164883277362c465afe /benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py
parentUpdate files/patch-spe-config (and with that our local adjustments to (diff)
[NEW] benchmarks/py-locust: Python utility for doing distributed load tests
Locust is an easy-to-use, distributed, user load testing tool. It is intended for load-testing web sites (or other systems) and figuring out how many concurrent users a system can handle. The behavior of each locust (or test user if you will) is defined by you and the swarming process is monitored from a web UI in real-time. This will help you battle test and identify bottlenecks in your code before letting real users in. WWW: https://locust.io/ Approved by: araujo (mentor), rene (mentor) Sponsored by: cleverbridge AG Differential Revision: https://reviews.freebsd.org/D18895
Diffstat (limited to 'benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py')
-rw-r--r--benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py b/benchmarks/py-locust/files/extra-EXAMPLES-custom_wait_function.py
new file mode 100644
index 000000000000..fad47c3174a6
--- /dev/null
+++ b/benchmarks/py-locust/files/extra-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 self: 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<max_wait:
+ break
+ return result
+
+class StrictWebsiteUser(HttpLocust):
+ """
+ Locust user class that makes exponential requests but strictly between two bounds.
+ """
+ host = "http://127.0.0.1:8089"
+ wait_function = lambda self: strictExp(self.min_wait, self.max_wait)*1000
+ task_set = UserTasks
+
+
+
+