23 lines
1.3 KiB
Python
23 lines
1.3 KiB
Python
"""Публичная нагрузка сообщений с отдельными cgroup CPU/memory snapshots."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
command = [sys.executable, '-X', 'utf8', 'tests/load.py', '--base-url', 'http://127.0.0.1:8085',
|
|
'--duration', '30', '--concurrency', '4', '--output', 'evidence/load-messages.json']
|
|
with (ROOT / 'evidence/load-messages-run.txt').open('w', encoding='utf-8') as output:
|
|
process = subprocess.Popen(command, cwd=ROOT, stdout=output, stderr=subprocess.STDOUT)
|
|
samples = []
|
|
start = time.monotonic()
|
|
while process.poll() is None:
|
|
ids = subprocess.check_output(['docker', 'compose', '-p', 'lyakhonov-lab5', 'ps', '-q'], cwd=ROOT, text=True).split()
|
|
stats = subprocess.check_output(['docker', 'stats', '--no-stream', '--format', '{{json .}}', *ids], text=True)
|
|
samples.append(dict(at_seconds=round(time.monotonic()-start, 3), containers=[json.loads(x) for x in stats.splitlines()]))
|
|
time.sleep(2)
|
|
code = process.wait()
|
|
(ROOT / 'evidence/load-messages-resources.json').write_text(json.dumps(dict(command=command, exit_code=code, samples=samples), indent=2), encoding='utf-8')
|
|
raise SystemExit(code)
|