forked from mtusi2026/mtusi2026lab3
Выполнена лабораторная работа 3
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import argparse
|
||||
import csv
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
|
||||
from research import OUT, benchmark, dataset, deploy
|
||||
|
||||
|
||||
def graph(rows):
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
import statistics
|
||||
selected = [row for row in rows if row['series'] == 'active-window']
|
||||
fig, axes = plt.subplots(1, 2, figsize=(11, 4), layout='constrained')
|
||||
groups = [[row['successful_rps'] for row in selected if row['pool'] == 8 and row['concurrency'] == count] for count in (4, 16, 64)]
|
||||
axes[0].errorbar([4, 16, 64], [statistics.mean(group) for group in groups], yerr=[(max(group)-min(group))/2 for group in groups], marker='o', capsize=4)
|
||||
axes[0].set(title='Synchronized active window, pool=8', xlabel='Concurrent clients', ylabel='Successful requests / second')
|
||||
groups = [[row['successful_rps'] for row in selected if row['pool'] == pool and row['concurrency'] == 64] for pool in (8, 1)]
|
||||
axes[1].bar(['pool=8', 'pool=1'], [statistics.mean(group) for group in groups], yerr=[(max(group)-min(group))/2 for group in groups], capsize=5, color=['#2563eb', '#16a34a'])
|
||||
axes[1].set(title='Paired comparison, 64 clients', ylabel='Successful requests / second')
|
||||
for axis in axes:
|
||||
axis.set_ylim(bottom=0)
|
||||
axis.grid(axis='y', alpha=0.25)
|
||||
fig.savefig(OUT / 'active-window.png', dpi=160)
|
||||
fig.savefig(OUT / 'active-window.svg')
|
||||
plt.close(fig)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--resume', action='store_true')
|
||||
args = parser.parse_args()
|
||||
rows = json.loads((OUT / 'results.json').read_text(encoding='utf-8'))
|
||||
if not args.resume:
|
||||
rows = [row for row in rows if row['series'] != 'active-window']
|
||||
completed = {row['repeat'] for row in rows if row['series'] == 'active-window'}
|
||||
environment = json.loads((OUT / 'environment.json').read_text(encoding='utf-8'))
|
||||
order = [(8, 4), (8, 16), (8, 64), (1, 64), (1, 64), (8, 64)]
|
||||
environment.setdefault('active_window_study', {'date_utc': datetime.now(timezone.utc).isoformat(), 'order_pool_concurrency': order, 'replicas': 4, 'cpu_each': 0.5, 'memory_mb_each': 256, 'duration_seconds': 15})
|
||||
environment['active_window_study']['dataset_at_resume' if args.resume else 'dataset_before'] = dataset()
|
||||
(OUT / 'environment.json').write_text(json.dumps(environment, indent=2), encoding='utf-8')
|
||||
try:
|
||||
for index, (pool, concurrency) in enumerate(order, 1):
|
||||
if index in completed:
|
||||
continue
|
||||
deploy(4, 0.5, 256, pool)
|
||||
print(f'Active window {index}/6: pool={pool}, clients={concurrency}', flush=True)
|
||||
result = benchmark(f'active-{index}-p{pool}-c{concurrency}', 15, concurrency, active=True)
|
||||
rows.append(dict(series='active-window', replicas=4, cpu_each=0.5, memory_mb_each=256, pool=pool, repeat=index, **result))
|
||||
(OUT / 'results.json').write_text(json.dumps(rows, indent=2), encoding='utf-8')
|
||||
environment['active_window_study']['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()
|
||||
Reference in New Issue
Block a user