diff --git a/app/config/base.py b/app/config/base.py index 825a694..918199a 100644 --- a/app/config/base.py +++ b/app/config/base.py @@ -15,7 +15,7 @@ class Config: class FlagFeatureSettings(BaseSettings): - CACHE_ENABLED: bool + CACHE_ENABLED: bool = False SENTRY_ENABLED: bool = False SLACK_ENABLED: bool = False diff --git a/compose.yaml b/compose.yaml index bade2f7..e988f28 100644 --- a/compose.yaml +++ b/compose.yaml @@ -101,7 +101,22 @@ services: - /:/host:ro networks: - fast-api-network - + locust-master: + image: locustio/locust + ports: + - "8089:8089" # Expose Locust's web interface on port 8089 + volumes: + - ./loadtests:/mnt/locust # Mount the loadtests directory into the container + command: -f /mnt/locust --master -H http://app:"${SERVER_PORT}" # Start Locust in master mode, pointing to your FastAPI application + networks: + - fast-api-network + locust-worker: + image: locustio/locust + volumes: + - ./loadtests:/mnt/locust # Mount the loadtests directory into the container + command: -f /mnt/locust --worker --master-host locust-master + networks: + - fast-api-network networks: fast-api-network: driver: bridge diff --git a/loadtests/__init__.py b/loadtests/__init__.py index e69de29..809ecc6 100644 --- a/loadtests/__init__.py +++ b/loadtests/__init__.py @@ -0,0 +1,5 @@ +from __future__ import annotations + +from loadtests.locustfile import LocustRunner + +__all__ = ["LocustRunner"] diff --git a/loadtests/home.py b/loadtests/home.py index 63a22d7..66ac0c4 100644 --- a/loadtests/home.py +++ b/loadtests/home.py @@ -1,10 +1,17 @@ from __future__ import annotations -from locust import HttpUser +from locust import constant from locust import task +from locust import TaskSet -class Home(HttpUser): +class Home(TaskSet): + wait_time = constant(1) + @task def home_endpoint(self): self.client.get("/api/home/") + + @task + def stop(self): + self.interrupt() diff --git a/loadtests/locustfile.py b/loadtests/locustfile.py new file mode 100644 index 0000000..af68974 --- /dev/null +++ b/loadtests/locustfile.py @@ -0,0 +1,8 @@ +from __future__ import annotations + +from home import Home +from locust import HttpUser + + +class LocustRunner(HttpUser): + tasks = [Home] diff --git a/locust.conf b/locust.conf new file mode 100644 index 0000000..ef62706 --- /dev/null +++ b/locust.conf @@ -0,0 +1,9 @@ +locustfile = ./loadtests +headless = false +master = false +expect-workers = 5 +host = http://0.0.0.0:8000 +users = 10 +spawn-rate = 10 +run-time = 3m +tags = [Critical, Normal] diff --git a/scripts/load_tests.sh b/scripts/load_tests.sh old mode 100644 new mode 100755 index 3de8308..771f6f1 --- a/scripts/load_tests.sh +++ b/scripts/load_tests.sh @@ -1,3 +1,3 @@ echo "Running load tests" echo -locust -f loadtests --headless --users 10 --spawn-rate 1 -t 2m -H http://0.0.0.0:8000 +locust