35 lines
1.9 KiB
Python
35 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Run public load without modifying it; sample scoped container resources DURING load."""
|
|
import datetime as dt
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import time
|
|
|
|
from grade4 import compose, db
|
|
|
|
|
|
def main():
|
|
before = int(db("print(conn.execute('SELECT count(*) FROM messages').fetchone()[0])"))
|
|
command = ['python3', 'tests/load.py', '--base-url', 'http://api:8080', '--duration', '15', '--concurrency', '4', '--output', 'evidence/load.json']
|
|
start = dt.datetime.now(dt.timezone.utc)
|
|
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
|
time.sleep(5)
|
|
assert process.poll() is None, 'load ended before resource sample'
|
|
sampled = dt.datetime.now(dt.timezone.utc)
|
|
containers = compose('ps', '-q', 'api', 'postgres', 'valkey').splitlines()
|
|
stats = subprocess.run(['docker', 'stats', '--no-stream', '--format', '{{.Name}} CPU={{.CPUPerc}} Memory={{.MemUsage}}', *containers], capture_output=True, text=True, check=True, timeout=10).stdout
|
|
assert process.poll() is None, 'load ended during resource sample'
|
|
output, _ = process.communicate(timeout=45)
|
|
assert process.returncode == 0, 'public load failed'
|
|
end = dt.datetime.now(dt.timezone.utc)
|
|
after = int(db("print(conn.execute('SELECT count(*) FROM messages').fetchone()[0])"))
|
|
summary = ('Command: ' + ' '.join(command) + '\nStart UTC: ' + start.isoformat() + '\nSample UTC: ' + sampled.isoformat() + '\nEnd UTC: ' + end.isoformat() + '\nWarm-up: completed functional checks; no separate timed warm-up. One run.\nDataset: dedicated new load chat starts empty; total PG message rows before=%d after=%d\n' % (before, after) + 'One live docker stats sample during load; neither average nor peak.\n' + stats)
|
|
Path('evidence/load-resources.txt').write_text(summary)
|
|
print(output.strip())
|
|
print(summary)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|