From cfeeaf79502b2fc044132a2a6a2c0174e22ab5ed Mon Sep 17 00:00:00 2001
From: Seva <seva@binarytrails.net>
Date: Mon, 17 Jun 2019 13:57:46 -0400
Subject: [PATCH] tools: add listen & subscribe to proxy_benchmark

---
 tools/proxy_benchmark.py | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/proxy_benchmark.py b/tools/proxy_benchmark.py
index 85cf2682..b09a172a 100644
--- a/tools/proxy_benchmark.py
+++ b/tools/proxy_benchmark.py
@@ -14,7 +14,12 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <https://www.gnu.org/licenses/>.
 #
-# Run with: locust -f proxy_benchmark.py --host http://127.0.0.1:8080
+# Manually run with Web UI:
+#   locust -f proxy_benchmark.py --host http://127.0.0.1:8080
+#
+# Run in Terminal:
+#   locust -f proxy_benchmark.py --host http://127.0.0.1:8080 \
+#       --clients 100 --hatch-rate 1 --run-time 10s --no-web --only-summary
 
 from locust import HttpLocust, TaskSet
 from random import randint
@@ -48,15 +53,27 @@ def get_key(l):
 def get_stats(l):
     l.client.get("/stats")
 
+def subscribe(l):
+    key = rand_list_value(words)
+    print("Subscribe: key={}".format(key))
+    l.client.get("/" + key + "/subscribe")
+
+def listen(l):
+    key = rand_list_value(words)
+    print("Listen: key={}".format(key))
+    l.client.get("/" + key + "/listen")
+
 class UserBehavior(TaskSet):
-    tasks = {get_key: 1, put_key: 1}
+    tasks = {get_key: 5, put_key: 5, get_stats: 1, subscribe: 1, listen: 1}
 
     def on_start(self):
         put_key(self)
         get_key(self)
+        subscribe(self)
+        listen(self)
 
     def on_stop(self):
-        get_stats()
+        get_stats(self)
 
 class WebsiteUser(HttpLocust):
     task_set = UserBehavior
-- 
GitLab