-
Notifications
You must be signed in to change notification settings - Fork 0
Добавлен скрипт для нагрузочного тестирования #5
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
Open
llirikhh
wants to merge
7
commits into
main
Choose a base branch
from
test_load
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c5b138
Добавлен скрипт для нагрузочного тестирования
llirikhh d22164a
Добавлен график по всем количествам воркеров
llirikhh 37d486d
Delete DS_Store
llirikhh e19df23
Multythreading is added to script
llirikhh 74f85c0
Merge branch 'main' into test_load
VS-CDR d0bca1a
Add discription of load testing
llirikhh 59675ae
Merge branch 'test_load' of github.com:Rattysed/distributed-image-con…
llirikhh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,5 +7,9 @@ backend/media | |
|
|
||
| backend/celerybeat-schedule | ||
|
|
||
| test/assets | ||
| test/data | ||
| test/graphs | ||
|
|
||
| .idea | ||
| .env | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import os | ||
| import json | ||
| import re | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
| from collections import defaultdict | ||
|
|
||
| # Путь к папке с файлами | ||
| DATA_DIR = "./data" | ||
| OUTPUT_DIR = "graphs" | ||
| os.makedirs(OUTPUT_DIR, exist_ok=True) | ||
|
|
||
| # Хранилища | ||
| data_by_worker_and_size = defaultdict(list) | ||
| summary_by_size = defaultdict(lambda: defaultdict(list)) | ||
|
|
||
| # Регулярка для парсинга имени файла | ||
| pattern = re.compile(r"workers-(\d+)_size-(\w+)_count-(\d+)\.json") | ||
|
|
||
| # Чтение файлов | ||
| for file_name in os.listdir(DATA_DIR): | ||
| match = pattern.match(file_name) | ||
| if not match: | ||
| continue | ||
|
|
||
| workers = int(match.group(1)) | ||
| size = match.group(2) | ||
| count = int(match.group(3)) | ||
|
|
||
| with open(os.path.join(DATA_DIR, file_name), "r") as f: | ||
| data = json.load(f) | ||
| times = data["times"] | ||
|
|
||
| data_by_worker_and_size[(workers, size)].append((count, times)) | ||
| mean_time = np.mean(times) | ||
| summary_by_size[size][workers].append((count, mean_time)) | ||
|
|
||
| for (workers, size), batch_data in data_by_worker_and_size.items(): | ||
| batch_data.sort(key=lambda x: x[0]) | ||
|
|
||
| counts, mins, maxs, means, medians = [], [], [], [], [] | ||
|
|
||
| for count, times in batch_data: | ||
| times_np = np.array(times) | ||
| counts.append(count) | ||
| mins.append(np.min(times_np)) | ||
| maxs.append(np.max(times_np)) | ||
| means.append(np.mean(times_np)) | ||
| medians.append(np.median(times_np)) | ||
|
|
||
| plt.figure(figsize=(10, 6)) | ||
| plt.plot(counts, maxs, label="Максимум", color="red") | ||
| plt.plot(counts, mins, label="Минимум", color="blue") | ||
| plt.plot(counts, means, label="Среднее", color="green") | ||
| plt.plot(counts, medians, label="Медиана", color="orange") | ||
| plt.fill_between(counts, mins, maxs, color="gray", alpha=0.2, label="Диапазон (мин-макс)") | ||
|
|
||
| plt.xlabel("Количество запросов") | ||
| plt.ylabel("Время обработки (сек)") | ||
| plt.title(f"Размер: {size}, Воркеры: {workers}") | ||
| plt.legend() | ||
| plt.grid(True) | ||
| plt.tight_layout() | ||
|
|
||
| filename = f"size-{size}_workers-{workers}.png" | ||
| plt.savefig(os.path.join(OUTPUT_DIR, filename)) | ||
| plt.close() | ||
|
|
||
| # Сводные графики: сравнение воркеров (только среднее время) | ||
| for size, workers_data in summary_by_size.items(): | ||
| plt.figure(figsize=(10, 6)) | ||
| for workers, datapoints in sorted(workers_data.items()): | ||
| datapoints.sort(key=lambda x: x[0]) | ||
| counts = [x[0] for x in datapoints] | ||
| means = [x[1] for x in datapoints] | ||
| plt.plot(counts, means, label=f"{workers} воркеров") | ||
|
|
||
| plt.xlabel("Количесвто запросов)") | ||
| plt.ylabel("Среднее время обработки (сек)") | ||
| plt.title(f"Сравнение по воркерам — размер изображения: {size}") | ||
| plt.legend() | ||
| plt.grid(True) | ||
| plt.tight_layout() | ||
|
|
||
| filename = f"size-{size}_summary.png" | ||
| plt.savefig(os.path.join(OUTPUT_DIR, filename)) | ||
| plt.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import requests | ||
| import json | ||
| import time | ||
| import argparse | ||
| import os | ||
|
|
||
| def get_correct_image_path(size): | ||
| for filename in os.listdir("./assets"): | ||
| if size in filename: | ||
| return f"./assets/{filename}" | ||
|
|
||
| print(f"Невозможно найти изображение, содержащее {size} в названии") | ||
| exit(0) | ||
|
|
||
| def get_request_ids(size, count): | ||
| print("[1] Отправление изображений") | ||
|
|
||
| request_ids = [] | ||
|
|
||
| for i in range(count): | ||
| url_upload = 'http://localhost/api/upload/' | ||
| files = {'files': open(get_correct_image_path(size), 'rb')} | ||
| response_upload = requests.post(url_upload, files=files, allow_redirects=True) | ||
| request_id = json.loads(response_upload.text)['id'] | ||
| request_ids.append(request_id) | ||
|
|
||
| print("[1] Изображения отправлены") | ||
|
|
||
| return request_ids | ||
|
|
||
| def get_exec_times(request_ids): | ||
| print("[2] Получение времени обработки изображений") | ||
|
|
||
| exec_times = [] | ||
|
|
||
| for request_id in request_ids: | ||
| # Waiting till the end of image proccesing | ||
| url_status = f'http://localhost/api/status/{request_id}/' | ||
| sleep_duration = 0.0 | ||
| sleep_addition = 0.5 | ||
| while json.loads(requests.get(url_status).text)['status'] != 'ready': | ||
| sleep_duration += sleep_addition | ||
| time.sleep(sleep_duration) | ||
|
|
||
| # Get the processing time | ||
| url_exec_time = f'http://localhost/request/exec_time/{request_id}/' | ||
| response_exec_time = requests.get(url_exec_time) | ||
| exec_time = json.loads(response_exec_time.text)['seconds'] | ||
| exec_times.append(exec_time) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и здесь тоже |
||
|
|
||
| print("[2] Информация по всем изображениям получена") | ||
|
|
||
| return exec_times | ||
|
|
||
| def save_data(count_workers, count, size, exec_times): | ||
| filename = f'./data/workers-{count_workers}_size-{size}_count-{count}.json' | ||
| dirname = os.path.dirname(filename) | ||
|
|
||
| if not os.path.exists(dirname): | ||
| os.mkdir(dirname) | ||
|
|
||
| data = { | ||
| 'workers-count': count_workers, | ||
| 'count': count, | ||
| 'size': size, | ||
| 'times': exec_times | ||
| } | ||
|
|
||
| with open(filename, 'w') as file: | ||
| json.dump(data, file) | ||
|
|
||
| print(f'[3] Время обработки изображений записано в {filename}\n') | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(description='Получить время выполнения --count POST-запросов с изображениями размера --size в секундах') | ||
|
|
||
| parser.add_argument('--workers-count', required=True, type=int, help='Количество воркеров') | ||
| parser.add_argument('--count', required=True, type=int, help='Количество запросов') | ||
| parser.add_argument('--size', required=True, choices=['small', 'big'], help='Размер изображения') | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| print(f"[0] {args.count} {args.size}".upper()) | ||
|
|
||
| request_ids = get_request_ids(size=args.size, count=args.count) | ||
| exec_times = get_exec_times(request_ids=request_ids) | ||
|
|
||
| save_data(count_workers=args.workers_count, count=args.count, size=args.size, exec_times=exec_times) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| altgraph==0.17.2 | ||
| certifi==2025.1.31 | ||
| charset-normalizer==3.4.1 | ||
| contourpy==1.3.0 | ||
| cycler==0.12.1 | ||
| fonttools==4.57.0 | ||
| future==0.18.2 | ||
| idna==3.10 | ||
| importlib_resources==6.5.2 | ||
| kiwisolver==1.4.7 | ||
| macholib==1.15.2 | ||
| matplotlib==3.9.4 | ||
| numpy==2.0.2 | ||
| packaging==24.2 | ||
| pillow==11.2.1 | ||
| pip==21.2.4 | ||
| pyparsing==3.2.3 | ||
| python-dateutil==2.9.0.post0 | ||
| requests==2.32.3 | ||
| setuptools==58.0.4 | ||
| six==1.15.0 | ||
| urllib3==1.26.6 | ||
| wheel==0.37.0 | ||
| zipp==3.21.0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше конечно не в цикле это делать, а через ThreadPool executor