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

Fastapi refactor #6666

Merged
merged 2 commits into from
Dec 24, 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
22 changes: 0 additions & 22 deletions locust/locustfile.py

This file was deleted.

3 changes: 3 additions & 0 deletions scripts/locust/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM python:3.11-slim
WORKDIR /app/locust
RUN pip install locust
15 changes: 15 additions & 0 deletions scripts/locust/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
locust:
build:
context: .
dockerfile: Dockerfile
ports:
- "8089:8089" # Expose Locust web UI
volumes:
- ./:/app/locust
working_dir: /app/locust
entrypoint: locust -f /app/locust/locustfile.py
environment:
LOCUST_HOST: "https://tm-fastapi.naxa.com.np"
Empty file.
74 changes: 74 additions & 0 deletions scripts/locust/locustfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
from locust import HttpUser, TaskSet, task, between

class ProjectAndComments(TaskSet):
@task
def get_project(self):
self.client.get("/api/v2/projects/114/")

@task
def get_comments(self):
self.client.get("/api/v2/projects/114/comments/")

class ProjectList(TaskSet):
@task
def get_project(self):
self.client.get("/api/v2/projects/")

class GetSimilarProjects(TaskSet):
@task
def get_similar_projects(self):
self.client.get("/api/v2/projects/queries/114/similar-projects/")

class GetContributions(TaskSet):
@task
def get_contributions(self):
self.client.get("/api/v2/projects/114/contributions/")

class GetContributionsByDay(TaskSet):
@task
def get_contributions_by_day(self):
self.client.get("/api/v2/projects/114/contributions/queries/day/")

class GetStatistics(TaskSet):
@task
def get_statistics(self):
self.client.get("/api/v2/system/statistics/")

class GetActionAny(TaskSet):
@task
def get_action_any(self):
self.client.get("/api/v2/projects/?action=any")

# Mapping task names to classes
task_mapping = {
"project_and_comments": ProjectAndComments,
"similar_projects": GetSimilarProjects,
"contributions": GetContributions,
"contributions_by_day": GetContributionsByDay,
"statistics": GetStatistics,
"action_any": GetActionAny,
}

# User class
class ApiBenchmarkUser(HttpUser):
wait_time = between(1, 2)

# Dynamically select tasks based on environment variable or CLI parameter
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
task_name = os.getenv("TASK_SET", "get_contributions").lower()
print(task_name, "The task name....")
self.tasks = [task_mapping.get(task_name, GetContributions)]


'''
/api/v2/projects/?action=any&omitMapResults=true
/api/v2/projects/114/
/api/v2/projects/114/comments/
/api/v2/projects/queries/114/similar-projects/
/api/v2/projects/114/contributions/
/api/v2/projects/114/contributions/queries/day/
/api/v2/system/statistics/
/api/v2/projects/?action=any
'''
Loading