core-time-tradeoff 2.2 KB

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