Skip to content

86: generator tcp-udp#89

Open
LapshinAE0 wants to merge 1 commit intomainfrom
86_TCP_UDP_clients
Open

86: generator tcp-udp#89
LapshinAE0 wants to merge 1 commit intomainfrom
86_TCP_UDP_clients

Conversation

@LapshinAE0
Copy link
Collaborator

No description provided.

Copy link
Member

@KonstantinKondratenko KonstantinKondratenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно исправить, после исправлений запустить на qemu под risc-v, приоверить, что работает


def check():
parser = argparse.ArgumentParser(
description="Генератор трафика с контролем RPS и таймаутами",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давайте на английском языке писать

Comment on lines +46 to +58

if args.quantity <= 0:
print("Ошибка: количество запросов должно быть положительным числом")
sys.exit(1)
if args.rps <= 0:
print("Ошибка: RPS должно быть положительным числом, используем значение по умолчанию 10")
args.rps = 10
if args.timeout <= 0:
print("Ошибка: таймаут должен быть положительным числом, используем значение по умолчанию 5")
args.timeout = 5
if args.max_concurrent <= 0:
print("Ошибка: количество одновременно выполеняемых задач должно быть положительным числом, используем значение по умолчанию 50")
args.max_concurrent = 50

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

аналогично про язык

Comment on lines +76 to +78
process = await asyncio.create_subprocess_exec('./generate_traf.sh', '1',\
site, stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL)
await asyncio.wait_for(process.communicate(), timeout=timeout)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему не использовать request -- зачем именно bash скрипты отдельный и subprocess

await process.wait()
return site, 1

def log(quantity, rps, timeout, max_concurrent, results):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для логов есть модуль logging -- лучше использовать его, а не писать с нуля

Асинхронный генератор трафика для тестирования сетевых подключений. Запускает заданное количество запросов к случайным сайтам из списка с контролем RPS (requests per second), таймаутами и ограничением параллельных задач. Результаты сохраняются в JSON-лог.


generate_traf.py -- основной скрипт на Python

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нет такого скрипта

Comment on lines +47 to +57
if args.quantity <= 0:
print("Ошибка: количество запросов должно быть положительным числом")
sys.exit(1)
if args.rps <= 0:
print("Ошибка: RPS должно быть положительным числом, используем значение по умолчанию 10")
args.rps = 10
if args.timeout <= 0:
print("Ошибка: таймаут должен быть положительным числом, используем значение по умолчанию 5")
args.timeout = 5
if args.max_concurrent <= 0:
print("Ошибка: количество одновременно выполеняемых задач должно быть положительным числом, используем значение по умолчанию 50")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

странная логика -- почему некорректный quantity приводит к sys.exit, а все остальное нет?
Давайте одной придерживаться логики

except asyncio.TimeoutError:
process.kill()
await process.wait()
return site, 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

магисческие числа -- плохо, они тут не очевидны, сделайте какой-нибудь enum, чтобы было понятно что это за абстрактные +-1 0 и тд

"--quantity", "-q",
type=int,
default=10,
help="Количество запросов (обязательный параметр)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему вы пишете, что параметр обязательный, при этом у него default=10?

import json


def check():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

плохой нейминг -- у вас функция по сути парсер аргументов и чтение файла, почему она называется check?

check_one и check по логике названия должны быть примрено одинаковые, а на деле разные

Comment on lines +154 to +168

tasks = []
for _ in range(quantity):
site = random.choice(sites)
async def task_wrapper():
async with semaphore:
return await check_one(site, timeout)

task = asyncio.create_task(task_wrapper())
tasks.append(task)

await asyncio.sleep(delay)

results = await asyncio.gather(*tasks, return_exceptions=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У вас тут замыкание, при запуске с параметрами
python3 generate_rand_traf.py --quantity 10 --rps 10 --max_concurrent 1 --timeout 10 запросы будут на два адреса -- на 1 случайные и (quantity-1) один и тот же

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Разработка виртуальных клиентов TCP\UDP

2 participants