generate_graphs.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/python3
  2. #
  3. # This script assumes that the set of CSV files produced by "generate_csv.sh" is provided as input
  4. # and that locally there is the "results" folder.
  5. #
  6. # results for TCP:
  7. INPUT_FILE_PUSHPULL_TCP_THROUGHPUT="results/pushpull_tcp_thr_results.csv"
  8. INPUT_FILE_REQREP_TCP_LATENCY="results/reqrep_tcp_lat_results.csv"
  9. TCP_LINK_GPBS=100
  10. # results for INPROC:
  11. INPUT_FILE_PUSHPULL_INPROC_THROUGHPUT="results/pushpull_inproc_thr_results.csv"
  12. INPUT_FILE_PUBSUBPROXY_INPROC_THROUGHPUT="results/pubsubproxy_inproc_thr_results.csv"
  13. # dependencies
  14. #
  15. # pip3 install matplotlib
  16. #
  17. import matplotlib.pyplot as plt
  18. import numpy as np
  19. # functions
  20. def plot_throughput(csv_filename, title, is_tcp=False):
  21. message_size_bytes, message_count, pps, mbps = np.loadtxt(csv_filename, delimiter=',', unpack=True)
  22. fig, ax1 = plt.subplots()
  23. # PPS axis
  24. color = 'tab:red'
  25. ax1.set_xlabel('Message size [B]')
  26. ax1.set_ylabel('PPS [Mmsg/s]', color=color)
  27. ax1.semilogx(message_size_bytes, pps / 1e6, label='PPS [Mmsg/s]', marker='x', color=color)
  28. ax1.tick_params(axis='y', labelcolor=color)
  29. # GBPS axis
  30. color = 'tab:blue'
  31. ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
  32. ax2.set_ylabel('Throughput [Gb/s]', color=color)
  33. ax2.semilogx(message_size_bytes, mbps / 1e3, label='Throughput [Gb/s]', marker='o')
  34. if is_tcp:
  35. ax2.set_yticks(np.arange(0, TCP_LINK_GPBS + 1, TCP_LINK_GPBS/10))
  36. ax2.tick_params(axis='y', labelcolor=color)
  37. ax2.grid(True)
  38. plt.title(title)
  39. fig.tight_layout() # otherwise the right y-label is slightly clippe
  40. plt.savefig(csv_filename.replace('.csv', '.png'))
  41. plt.show()
  42. def plot_latency(csv_filename, title):
  43. message_size_bytes, message_count, lat = np.loadtxt(csv_filename, delimiter=',', unpack=True)
  44. plt.semilogx(message_size_bytes, lat, label='Latency [us]', marker='o')
  45. plt.xlabel('Message size [B]')
  46. plt.ylabel('Latency [us]')
  47. plt.grid(True)
  48. plt.title(title)
  49. plt.savefig(csv_filename.replace('.csv', '.png'))
  50. plt.show()
  51. # main
  52. plot_throughput(INPUT_FILE_PUSHPULL_TCP_THROUGHPUT, 'ZeroMQ PUSH/PULL socket throughput, TCP transport', is_tcp=True)
  53. plot_throughput(INPUT_FILE_PUSHPULL_INPROC_THROUGHPUT, 'ZeroMQ PUSH/PULL socket throughput, INPROC transport')
  54. plot_throughput(INPUT_FILE_PUBSUBPROXY_INPROC_THROUGHPUT, 'ZeroMQ PUB/SUB PROXY socket throughput, INPROC transport')
  55. plot_latency(INPUT_FILE_REQREP_TCP_LATENCY, 'ZeroMQ REQ/REP socket latency, TCP transport')