Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat - load testing added #39

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This repository provides a template for creating and deploying a FastAPI project

- [Features](#features)
- [Getting started](#getting-started)
- [Advanced Usage](#advanced-usage)

### Features

Expand All @@ -28,6 +29,8 @@ This repository provides a template for creating and deploying a FastAPI project
- Application monitoring using Signoz
- Feature flagging added - User can enabled/disabled
- Database Monitoring using percona
- Loadtests using locust

### Getting Started

#### Requirements:
Expand Down Expand Up @@ -144,7 +147,9 @@ async def external_service_endpoint():
raise HTTPException(status_code=503, detail="Service temporarily unavailable")
```

# Using Signoz Monitoring Tool
### Advanced Usage

#### Using Signoz Monitoring Tool

To utilize Signoz for monitoring your applications, follow these steps:

Expand Down Expand Up @@ -179,7 +184,7 @@ To utilize Signoz for monitoring your applications, follow these steps:
OTEL_EXPORTER_OTLP_PROTOCOL=
```

## Logging with Signoz
#### Logging with Signoz

To enable logging with Signoz, follow these steps:

Expand All @@ -196,7 +201,8 @@ To enable logging with Signoz, follow these steps:
- Follow the instructions provided to configure log sending to Signoz.

By following these steps, you can effectively set up application monitoring and logging using Signoz for your Python FastAPI applications.
### Database Monitoring Using Percona

#### Database Monitoring Using Percona

To monitor your database using Percona, follow these steps:

Expand Down Expand Up @@ -230,8 +236,15 @@ To monitor your database using Percona, follow these steps:

By following these steps, you'll successfully configure Percona to monitor your MySQL database.

### Dashboard Links
#### Dashboard Links
- Percona: https://localhost:443
- flower: http://localhost:5556
- server: http://localhost:8000
- locust: http://localhost:8089
- server-healthcheck: http://localhost:8000/home
himanshu-wedensday marked this conversation as resolved.
Show resolved Hide resolved


#### Useful scripts
- Tests - scripts/run_tests.sh
- Linting & Formatting - scripts/lint_and_format.sh
- Load tests - scripts/load_tests.sh (Change [locust.conf](https://docs.locust.io/en/stable/configuration.html) accordinly)
2 changes: 1 addition & 1 deletion app/middlewares/rate_limiter_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from app.config.redis_config import get_redis_pool

MAX_REQUESTS = 10
MAX_REQUESTS = 10000
TIME_WINDOW = 60


Expand Down
1 change: 0 additions & 1 deletion app/routes/users/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from app.daos.users import get_user as get_user_dao
from app.daos.users import list_users as list_users_dao
from app.daos.users import login as signin
from app.middlewares.request_id_injection import request_id_contextvar
from app.schemas.users.users_request import CreateUser
from app.schemas.users.users_request import Login
from app.schemas.users.users_response import UserOutResponse
Expand Down
17 changes: 16 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file added loadtests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions loadtests/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

from locust import HttpUser
from locust import task


class Home(HttpUser):
@task
def home_endpoint(self):
self.client.get("/api/home/")
8 changes: 8 additions & 0 deletions locust.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locustfile = ./loadtests
headless = true
master = false
expect-workers = 5
host = http://0.0.0.0:8000
users = 100
spawn-rate = 10
run-time = 10m
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ iniconfig==2.0.0
itsdangerous
joblib==1.2.0
langchain
locust>=2.0
lxml==4.9.2
lz4==4.3.2
Markdown==3.4.3
Expand Down
3 changes: 3 additions & 0 deletions scripts/load_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo "Running load tests"
echo
locust
Loading