run_experiments.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/usr/bin/python3
  2. import subprocess
  3. import os
  4. import sys
  5. import math
  6. import time
  7. from gen_manifest import generate_manifest
  8. from gen_enclave_config import generate_config
  9. from logs_to_csv import parse_output_logs
  10. from core_allocator import core_allocation
  11. ###############################################################################
  12. # CONFIGS TO SET:
  13. # NUM_DIAGNOSTIC_EPOCHS = 4
  14. ###############################################################################
  15. def epoch_time_estimate(n, m, t, b):
  16. # Base epoch time is 5 sec
  17. etime_base = 5
  18. clients_per_server = math.ceil(n/m)
  19. # Using 8 sec for 2^20 clients in route_compute time as the base for calculations below
  20. etime_route_compute = 0.8 * math.ceil(clients_per_server/100000)
  21. etime_precompute = 1 * math.ceil(clients_per_server/100000)
  22. # Costs for Waksman network precompute
  23. # ID channels needs 6 WN, token channel needs 3 WNs
  24. etime_precompute *=5
  25. # Client time:
  26. # Takes about 30 sec for handling 2^20 clients
  27. etime_client = 3 * math.ceil(clients_per_server/50000)
  28. if m==2 or m==3:
  29. etime_client += 60
  30. etime = etime_base + etime_precompute + etime_route_compute + etime_client
  31. return int(etime)
  32. def run_exp(LOG_FOLDER, TOKEN_CHANNEL, NUM_EPOCHS, N, M, T, B, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN):
  33. if not os.path.exists(LOG_FOLDER):
  34. os.mkdir(LOG_FOLDER)
  35. if TOKEN_CHANNEL:
  36. LOG_FOLDER = LOG_FOLDER + "Token/"
  37. else:
  38. LOG_FOLDER = LOG_FOLDER + "ID/"
  39. if not os.path.exists(LOG_FOLDER):
  40. os.mkdir(LOG_FOLDER)
  41. #DIAGNOSTIC_FOLDER = LOG_FOLDER + "diagnostic/"
  42. #if not os.path.exists(DIAGNOSTIC_FOLDER):
  43. # os.mkdir(DIAGNOSTIC_FOLDER)
  44. for t in T:
  45. b = B
  46. for m in M:
  47. for n in N:
  48. #for run in ["diagnostic", "experiment"]:
  49. for run in ["experiment"]:
  50. (servers_allocation, client_allocation) = \
  51. core_allocation(m,t)
  52. if servers_allocation is None or \
  53. client_allocation is None:
  54. print("""
  55. ***
  56. *** Not enough physical cores available to run
  57. *** M = %d servers with T = %d cores each, plus
  58. *** at least one core for clients.
  59. ***
  60. *** Consider setting the env var OVERLOAD_CORES=1
  61. *** (which will severely impact the performance)
  62. *** or run experiments of reduced size.
  63. ***
  64. """ % (m,t))
  65. continue
  66. num_WN_to_precompute = 0
  67. if TOKEN_CHANNEL:
  68. num_WN_to_precompute = 2 * 3
  69. else:
  70. num_WN_to_precompute = 2 * 6
  71. # Make the correct output folder for diagnostic/experiment
  72. experiment_name = str(n) + "_" + str(m) + "_" + str(t) + "_" + str(b) + "/"
  73. if run == "diagnostic":
  74. log_subfolder = DIAGNOSTIC_FOLDER
  75. elif run == "experiment":
  76. log_subfolder = LOG_FOLDER
  77. log_subfolder = log_subfolder + experiment_name
  78. if not os.path.exists(log_subfolder):
  79. os.mkdir(log_subfolder)
  80. if run == "diagnostic":
  81. print("\n\n Running %s diagnostic t = %d, m = %d, n = %d \n\n" %
  82. ("token channel" if TOKEN_CHANNEL else "ID channel", t, m, n))
  83. # Manifest generated by diagnostic can be reused by the actual experiment
  84. generate_manifest(n, m, t, b, TOKEN_CHANNEL, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)
  85. generate_config(n, m, t, b, TOKEN_CHANNEL, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN, num_WN_to_precompute)
  86. epoch_param = epoch_time_estimate(n, m, t, b)
  87. elif run == "experiment":
  88. #print("Waiting for 2 mins to reset sockets")
  89. #time.sleep(120)
  90. #num_sizes, pwn_max, epoch_max, scm_max = parse_output_logs(DIAGNOSTIC_FOLDER, experiment_name)
  91. #print("From logs_to_csv: num_sizes = %d, pwn_max = %f, epoch_max = %f, scm_max = %f"
  92. #% (num_sizes, pwn_max, epoch_max, scm_max))
  93. print("\n\n Running %s experiment t = %d, m = %d, n = %d \n\n" %
  94. ("token channel" if TOKEN_CHANNEL else "ID channel", t, m, n))
  95. #num_WN_to_precompute = math.ceil((num_sizes * pwn_max)/epoch_max)
  96. #print("num_WN_to_precompute = %d" %(num_WN_to_precompute))
  97. #if num_WN_to_precompute < 2 * num_sizes:
  98. # num_WN_to_precompute = 2 * num_sizes
  99. #print("num_WN_to_precompute (pushed up to min 2 sets) = %d" %(num_WN_to_precompute))
  100. #epoch_param = math.ceil(epoch_max + 10 * m * scm_max)
  101. generate_manifest(n, m, t, b, TOKEN_CHANNEL, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)
  102. epoch_param = epoch_time_estimate(n, m, t, b)
  103. generate_config(n, m, t, b, TOKEN_CHANNEL, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN, num_WN_to_precompute)
  104. # Either estimate from epoch_time_estimate for diagnostic
  105. # or the one we got from diagnostic run
  106. epoch_wait_time = math.ceil(epoch_param)
  107. print("Epoch_wait_time = %d" % epoch_wait_time)
  108. # Since launch is invoked from App/ we add a ../ to subfolder before
  109. # passing it to slaunch
  110. log_subfolder = "../" + log_subfolder
  111. slaunch = []
  112. slaunch.append("./launch")
  113. slaunch.append("route_clients")
  114. slaunch.append("-l")
  115. slaunch.append(log_subfolder)
  116. slaunch.append("-n")
  117. nodes_to_include = ["-n"]
  118. for i in range(1, m+1):
  119. nodes_to_include.append("s"+str(i))
  120. slaunch.append("s"+str(i))
  121. slaunch.append("-d")
  122. slaunch.append(str(epoch_wait_time))
  123. slaunch.append("-e")
  124. if run == "experiment":
  125. slaunch.append(str(NUM_EPOCHS))
  126. else:
  127. slaunch.append(str(NUM_DIAGNOSTIC_EPOCHS))
  128. if run == "experiment":
  129. slaunch.append("-w")
  130. slaunch.append(str(num_WN_to_precompute))
  131. os.chdir("./App")
  132. # Server outputs are captured by log files provided to each of the server
  133. # launch calls made by App/launch
  134. make = subprocess.call(["make", "-C", "..", "-j"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
  135. try:
  136. os.mkdir("keys")
  137. except:
  138. # It's OK if it already exists
  139. pass
  140. pubkeys = subprocess.call(["./getpubkeys"])
  141. server_process = subprocess.run(slaunch)
  142. claunch = []
  143. claunch.append("./clientlaunch")
  144. claunch.append("-t")
  145. claunch.append(str(len(client_allocation)))
  146. claunch.append("-l")
  147. claunch.append(log_subfolder+"clients.log")
  148. claunch.append("-T")
  149. claunch.append(",".join(map(str, client_allocation)))
  150. os.chdir("./../Client/")
  151. client_process = subprocess.call(claunch)
  152. os.chdir("./../")