Skip to content

Commit

Permalink
Added apache bencmark and middleware for stress testing
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Feb 22, 2024
1 parent 903650f commit 04ae0ea
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 1 deletion.
Binary file added backend/ab.exe
Binary file not shown.
Binary file added backend/abs.exe
Binary file not shown.
1 change: 1 addition & 0 deletions backend/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
# "apps.account.middleware.RedirectAuthenticatedMiddleware",
"middleware.metric.metric_middleware",
]

# !Root UrlConf
Expand Down
27 changes: 27 additions & 0 deletions backend/middleware/metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
import time


# ?metric_middleware
def metric_middleware(get_response):
def middleware(request):
# Get beginning stats
start_time = time.perf_counter()

# Process the request
response = get_response(request)

# Get ending stats
end_time = time.perf_counter()

# Calculate stats
total_time = end_time - start_time

# Log the results
logger = logging.getLogger("debug")
logger.info(f"Total time: {(total_time):.2f}s")
print(f"Total time: {(total_time):.2f}s")

return response

return middleware
17 changes: 16 additions & 1 deletion backend/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ django-lifecycle = "^1.1.2"
django-redis = "^5.4.0"
redis = "^5.0.1"
gunicorn = "^21.2.0"
waitress = "^3.0.0"


[tool.poetry.group.dev.dependencies]
Expand Down
4 changes: 4 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ Backend
- `poetry run pre-commit run --all-files`
- Generate api schema
- `poetry run manage.py spectacular --file schema.yml`
- Configure waitress
- `poetry run waitress-serve --listen=*:8000 config.wsgi:application`
- Stress test using Apache Benchmark
- `./ab -c 10 -n 20 http://127.0.0.1:8000/pets/`

0 comments on commit 04ae0ea

Please sign in to comment.