#!/usr/bin/env python3 """Render measured pipeline results; install requirements-research.txt first.""" import argparse import json import os from pathlib import Path import tempfile def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('input', nargs='?', type=Path, default=Path('evidence/lab5-research.json')) args = parser.parse_args() os.environ['MPLCONFIGDIR'] = str(Path(tempfile.gettempdir()) / 'mtusi-lab5-matplotlib') import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt report = json.loads(args.input.read_text()) assert report.get('result') == 'PASS', 'plot only completed experiments' cases = report['cases'] metrics = [ ('throughput_rps', 'Throughput, images/s', 1), ('ready_p95_ms', 'p95 POST start → ready, s', .001), ('queue_lag_peak_seconds', 'Peak queued job age, s', 1), ('rss_peak_bytes', 'Sampled worker + child RSS, MiB', 1 / 1024**2), ] plt.rcParams.update({'font.size': 10, 'axes.spines.top': False, 'axes.spines.right': False}) figure, axes = plt.subplots(2, 2, figsize=(10, 7), layout='constrained') for axis, (metric, label, factor) in zip(axes.flat, metrics): for width in sorted({case['width'] for case in cases}): series = sorted([case for case in cases if case['width'] == width], key=lambda c: c['concurrency']) axis.plot(range(len(series)), [case[metric] * factor for case in series], marker='o', linewidth=2, label=str(width) + ' × ' + str(series[0]['height'])) axis.set_xticks(range(len(series)), [str(c['concurrency']) + '/' + str(c['prefetch']) for c in series]) axis.set_xlabel('Concurrency / prefetch') axis.set_ylabel(label) axis.set_ylim(bottom=0) axis.grid(axis='y', alpha=.25) axis.legend(title='PNG pixels') figure.suptitle('Redis Streams image pipeline — finite burst on one host\n' + str(report['requests_per_case']) + ' images per case; sampled RSS and queue lag', fontsize=13) for suffix in ('.svg', '.png'): target = args.input.with_suffix(suffix) figure.savefig(target, dpi=180, metadata={'Creator': 'Matplotlib'}) print(target) plt.close(figure) if __name__ == '__main__': main()