Skip to content

Commit

Permalink
Automate stress testing process
Browse files Browse the repository at this point in the history
  • Loading branch information
riadelimemmedov committed Feb 24, 2024
1 parent ce67342 commit 1854f7c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
3 changes: 3 additions & 0 deletions backend/apps/pet/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
Expand All @@ -17,6 +18,7 @@ class PetView(APIView):

serializer_class = PetSerializer

# @cache_page(60)
def get(self, request):
"""
Retrieve a list of all pets.
Expand All @@ -28,6 +30,7 @@ def get(self, request):
Response: A response object containing the serialized data of all pets and the HTTP status code.
"""
pets = Pet.objects.all()
print("Cached dataaaaa")
serializer = self.serializer_class(pets, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

Expand Down
6 changes: 5 additions & 1 deletion backend/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,11 @@
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/1",
"LOCATION": "redis://{}:{}/{}".format(
config("REDIS_HOST"),
config("REDIS_PORT"),
config("REDIS_DB"),
),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
Expand Down
22 changes: 22 additions & 0 deletions backend/scripts/benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

import subprocess


# ?run_ab
def run_ab(url: str):
# http://127.0.0.1:8000/pets/
# Run the ab command with the specified parameters and capture the output
process = subprocess.Popen(
["./ab.exe", "-c 10", "-n 20", f"{url}"],
stdout=subprocess.PIPE,
universal_newlines=True,
)
# Wait for the process to finish and get the output
output, _ = process.communicate()

# Print the output
print("AB result is ", output)


run_ab("http://127.0.0.1:8000/pets/")
3 changes: 3 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ Backend
- `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/`

- `./ab -c 10 -n 20 http://localhost:8000/pets/`
chmod +x ./ab.exe
22 changes: 11 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ services:
container_name: redis
image: redis:alpine

frontend:
container_name: frontend
build: ./frontend/contract-ui/
ports:
- 5173:8001 #http://localhost:5173/
working_dir: /frontend/contract-ui/
volumes:
- type: bind
source: ./frontend/contract-ui/
target: /frontend/contract-ui/
tty: true
# frontend:
# container_name: frontend
# build: ./frontend/contract-ui/
# ports:
# - 5173:8001 #http://localhost:5173/
# working_dir: /frontend/contract-ui/
# volumes:
# - type: bind
# source: ./frontend/contract-ui/
# target: /frontend/contract-ui/
# tty: true

0 comments on commit 1854f7c

Please sign in to comment.