core-time-tradeoff 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python3
  2. """Compute the core-time tradeoff given the experimental results for
  3. the private and public channels"""
  4. import sys
  5. import csv
  6. import math
  7. if len(sys.argv)!=3:
  8. print(f"Usage: {sys.argv[0]} <PRIV.csv file> <PUB.csv file>")
  9. sys.exit(0)
  10. priv_file = open(sys.argv[1], 'r')
  11. pub_file = open(sys.argv[2], 'r')
  12. priv_input = csv.DictReader(priv_file)
  13. pub_input = csv.DictReader(pub_file)
  14. priv_data = sorted(
  15. filter(lambda row: row['T']=='1' and row['N']=='1048576', priv_input),
  16. key = lambda row: (int(row['T']), int(row['M']), int(row['N'])))
  17. pub_data = sorted(
  18. filter(lambda row: row['T']=='1' and row['N']=='1048576', pub_input),
  19. key = lambda row: (int(row['T']), int(row['M']), int(row['N'])))
  20. priv_times = [ ( int(row['M']),
  21. float(row['epoch_mean']) + float(row['bytes_max'])*8/13000000000,
  22. float(row['wn_mean']) ) for row in priv_data ]
  23. pub_times = [ ( int(row['M']),
  24. float(row['epoch_mean']) + float(row['bytes_max'])*8/13000000000,
  25. float(row['wn_mean']) ) for row in pub_data ]
  26. # Sort the list of all times appearing in the data
  27. all_times = sorted([ tpl[1] for tpl in priv_times + pub_times ])
  28. # Interpolate 4 points between each pair of points in the sorted list
  29. # and flatten the result
  30. interp_times = [ x for xs in
  31. [[all_times[j] + i/5*(all_times[j+1]-all_times[j])
  32. for i in range(5)] for j in range(len(all_times)-1)]
  33. for x in xs ] + [ all_times[-1] ]
  34. for target_time in interp_times:
  35. # Find the smallest public and private channel configurations that
  36. # are at or below the target time
  37. try:
  38. priv_conf = next(filter(lambda tpl: tpl[1] <= target_time, priv_times))
  39. pub_conf = next(filter(lambda tpl: tpl[1] <= target_time, pub_times))
  40. priv_cores = math.ceil((1 + priv_conf[2] / target_time) * priv_conf[0])
  41. pub_cores = math.ceil((1 + pub_conf[2] / target_time) * pub_conf[0])
  42. print (target_time, priv_conf[0], pub_conf[0], priv_cores,
  43. pub_cores, priv_cores + pub_cores)
  44. except:
  45. # One of the channels couldn't reach a time as small as the
  46. # other channel could
  47. pass