Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ publish/


appsettings.Development.json

scripts/.env
scripts/.venv
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/load_testing/images/total_rqps_5min_100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions docs/load_testing/load_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# --- 5 Minute Tests ---
## "/" --> "/account" (50 users):
### Lightsail Instance Data:
![alt text](images/lightsail_cpu_5min.png)
### Locust Data:
![alt text](images/total_rqps_5_minutes.png)

## "/" --> "/account" (100 users):
### Lightsail Instance Data:
![alt text](images/lightsail_cpu_5min_100users.png)
### Locust Data:
![alt text](images/total_rqps_5min_100.png)


# Heavier workloads --- 5 Minute Tests ---
## "/" --> "/recipes" --> "/recipes/view/2" --> "/dashboard" (50 users)
### Lightsail Instance data:
![alt text](images/lightsail_cpu_5min_recipe.png)
### Locust Data:
![alt text](images/total_rqps_5min_recipe.png)

## "/" --> "/recipes" --> "/recipes/view/2" --> "/dashboard" (100 users)

### Lightsail Instance Data:
![alt text](images/lightsail_cpu_5min_100users_recipe.png)

### Locust Data:
![alt text](images/total_rqps_5min_100users_recipe.png)


## Pushing the limits --- 200 Users --- 15 minutes ---

### Lightsail Instance Data:
![alt text](images/lightsail_cpu_200users_15min.png)

### Locust Data:
![alt text](images/total_rqps_15min_200users.png)
61 changes: 61 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Getting Started

## Prerequisites

- Python 3.8+
- AWS Cognito credentials for the target environment

---

## Setup

**1. Create and activate a virtual environment**

```bash
python3 -m venv venv
source venv/bin/activate
```

**2. Install dependencies**

```bash
pip install -r requirements.txt
```

---

## Environment Variables

Create a `.env` file in the `scripts/` directory with the following:

```env
COGNITO_CLIENT_ID=your_client_id
COGNITO_CLIENT_SECRET=your_client_secret
COGNITO_USERNAME=your_username
COGNITO_PASSWORD=your_password
AWS_REGION=us-east-1
```

These credentials are used to authenticate against AWS Cognito before each load test run. The script calls `InitiateAuth` with `USER_PASSWORD_AUTH` flow and uses the returned `IdToken` as a Bearer token on all requests.

---

## Running Locust

Start the Locust web UI:

```bash
locust -f locustfile.py --host=https://culinary-command.com
```

Then open [http://localhost:8089](http://localhost:8089) to configure the number of users and spawn rate, and start the test.

To run headless (no UI):

```bash
locust -f locustfile.py --host=https://your-app-url.com --headless -u 50 -r 10 --run-time 1m
```

- `-u` — number of users
- `-r` — spawn rate (users per second)
- `--run-time` — how long to run the test
56 changes: 56 additions & 0 deletions scripts/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from locust import HttpUser, task, between
from dotenv import load_dotenv
import boto3
import hashlib
import hmac
import base64
import os

load_dotenv()

def get_secret_hash(username):
client_id = os.getenv("COGNITO_CLIENT_ID")
client_secret = os.getenv("COGNITO_CLIENT_SECRET")
message = username + client_id

dig = hmac.new(
client_secret.encode("utf-8"),
msg=message.encode("utf-8"),
digestmod=hashlib.sha256
).digest()
return base64.b64encode(dig).decode()

def get_cognito_token():
username = os.getenv("COGNITO_USERNAME")
client = boto3.client("cognito-idp", region_name=os.getenv("AWS_REGION"))
response = client.initiate_auth(
AuthFlow="USER_PASSWORD_AUTH",
AuthParameters={
"USERNAME": os.getenv("COGNITO_USERNAME"),
"PASSWORD": os.getenv("COGNITO_PASSWORD"),
"SECRET_HASH": get_secret_hash(username)
},
ClientId=os.getenv("COGNITO_CLIENT_ID"),
)
return response["AuthenticationResult"]["IdToken"]

class LocustLoadTesting(HttpUser):
wait_time = between(1, 3)

def on_start(self):
token = get_cognito_token()

self.client.headers.update({
"Authorization": f"Bearer {token}"
})

@task(3)
def browse_recipes(self):
self.client.get("/recipes", name="Browse Recipes")

def view_recipe(self):
recipe_id = 2
self.client.get(f"/recipes/view/{recipe_id}", name="View Recipe")

def view_dashboard(self):
self.client.get("/dashboard", name="View Dashboard")
3 changes: 3 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locust
boto3
python-dotenv
Loading