diff --git a/performance/locustfile.py b/performance/locustfile.py new file mode 100644 index 0000000..27f1002 --- /dev/null +++ b/performance/locustfile.py @@ -0,0 +1,32 @@ +import random +import threading + +from locust import HttpUser, TaskSet, task + + +class TokenTaskSet(TaskSet): + received_tokens = set() + token_lock = threading.Lock() + hosts = ["http://localhost:8080", "http://localhost:8081"] + + @task + def get_token(self): + host = random.choice(self.hosts) + with self.client.get(host + "/api/v1/token", catch_response=True) as response: + if response.status_code == 200: + token = response.text.strip() + with self.token_lock: + if token in self.received_tokens: + response.failure(f"Duplicate token found: {token}") + else: + response.success() + self.received_tokens.add(token) + else: + response.failure(f"Failed to get token from {host}, status code: {response.status_code}") + + +class User(HttpUser): + tasks = [TokenTaskSet] + + def on_start(self): + self.host = None diff --git a/performance/requirements.txt b/performance/requirements.txt new file mode 100644 index 0000000..ea6937c --- /dev/null +++ b/performance/requirements.txt @@ -0,0 +1,25 @@ +blinker==1.8.2 +Brotli==1.1.0 +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +ConfigArgParse==1.7 +Flask==3.0.3 +Flask-Cors==4.0.1 +Flask-Login==0.6.3 +gevent==24.2.1 +geventhttpclient==2.2.1 +greenlet==3.0.3 +idna==3.7 +itsdangerous==2.2.0 +Jinja2==3.1.4 +locust==2.27.0 +MarkupSafe==2.1.5 +msgpack==1.0.8 +psutil==5.9.8 +pyzmq==26.0.3 +requests==2.31.0 +urllib3==2.2.1 +Werkzeug==3.0.3 +zope.event==5.0 +zope.interface==6.4