forked from mtusi2026/mtusi2026lab3
33 lines
1.7 KiB
Python
33 lines
1.7 KiB
Python
import csv
|
|
from datetime import datetime, timezone
|
|
import json
|
|
|
|
from research import OUT, benchmark, dataset, deploy, graph
|
|
|
|
|
|
def main():
|
|
rows = json.loads((OUT / 'results.json').read_text(encoding='utf-8'))
|
|
environment = json.loads((OUT / 'environment.json').read_text(encoding='utf-8'))
|
|
environment['confirmation'] = {'date_utc': datetime.now(timezone.utc).isoformat(), 'order': [4, 2, 2, 4], 'duration_seconds': 15, 'concurrency': 24, 'cpu_total': 1, 'memory_total_mb': 512, 'dataset_before': dataset()}
|
|
try:
|
|
for index, replicas in enumerate((4, 2, 2, 4), 1):
|
|
deploy(replicas, 1/replicas, 512//replicas, 8)
|
|
print(f'Confirmation {index}/4: {replicas} replicas', flush=True)
|
|
result = benchmark(f'confirm-{index}-{replicas}', 15, 24)
|
|
rows.append(dict(series='confirmation', replicas=replicas, cpu_each=1/replicas, memory_mb_each=512//replicas, pool=8, repeat=index, **result))
|
|
(OUT / 'results.json').write_text(json.dumps(rows, indent=2), encoding='utf-8')
|
|
environment['confirmation']['dataset_after'] = dataset()
|
|
(OUT / 'environment.json').write_text(json.dumps(environment, indent=2), encoding='utf-8')
|
|
graph(rows)
|
|
fields = ['series', 'replicas', 'cpu_each', 'memory_mb_each', 'pool', 'repeat', 'concurrency', 'successful_rps', 'failed_requests', 'error_ratio']
|
|
with (OUT / 'results.csv').open('w', encoding='utf-8', newline='') as stream:
|
|
writer = csv.DictWriter(stream, fieldnames=fields, extrasaction='ignore')
|
|
writer.writeheader()
|
|
writer.writerows(rows)
|
|
finally:
|
|
deploy(2, 0.5, 256, 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|