run_all_experiments.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/python3
  2. import os
  3. import re
  4. import subprocess
  5. import sys
  6. from run_experiments import run_exp
  7. from epc_probe import get_max_epc_bytes
  8. def get_free_gib():
  9. """Get the number of free GiB of memory"""
  10. ret = subprocess.run(["free", "-m"], capture_output=True)
  11. if ret.returncode != 0:
  12. print("Unable to run free", file=sys.stderr)
  13. sys.exit(1)
  14. match = re.search(r'Mem:\s*\d+\s+\d+\s+(\d+)', str(ret.stdout))
  15. if match is None:
  16. print("Unable to parse output of free", file=sys.stderr)
  17. sys.exit(1)
  18. free_mem_mib = int(match.group(1))
  19. return free_mem_mib / 1024
  20. # How much memory is available?
  21. free_gib = get_free_gib()
  22. # How much EPC is available?
  23. epc_gib = get_max_epc_bytes() / (1<<30)
  24. LOG_FOLDER = "Experiments/"
  25. NUM_EPOCHS = 10
  26. TOKEN_OUT = 1
  27. TOKEN_IN = 1
  28. ID_OUT = 1
  29. ID_IN = 1
  30. # B = message size (bytes)
  31. B = 256
  32. N_MAX = 1<<20
  33. M_MAX = 72
  34. # For 1<<20 clients and 72 servers, we need 4.92 GiB of EPC and 20 GiB
  35. # of free RAM.
  36. # If we don't have that, abort, unless the SHRINK_TO_MEM env var is set
  37. # to 1, in which case perform smaller experiments that should fit in the
  38. # available resources.
  39. if epc_gib < 4.92 or free_gib < 20:
  40. shrink_to_mem = \
  41. os.getenv("SHRINK_TO_MEM", '0').lower() in ('true', '1', 't')
  42. if not shrink_to_mem:
  43. if epc_gib < 4.92:
  44. print(f"""
  45. *** Available EPC appears to be {epc_gib:.2f} GiB; 4.92 GiB is
  46. *** needed to run the full set of experiments.
  47. """)
  48. if free_gib < 20:
  49. print(f"""
  50. *** Free RAM appears to be {free_gib:.2f} GiB; 20 GiB is
  51. *** needed to run the full set of experiments.
  52. """)
  53. print("""
  54. *** Set the env var SHRINK_TO_MEM=1 to run a smaller set of
  55. *** experiments that should fit in the available resources.
  56. """)
  57. sys.exit(1)
  58. # Typical EPC sizes are slightly less than a power of 2.
  59. if epc_gib > 3.97 and free_gib > 14:
  60. N_MAX = 1<<19
  61. M_MAX = 72
  62. if epc_gib > 1.97 and free_gib > 14:
  63. N_MAX = 1<<19
  64. M_MAX = 36
  65. elif epc_gib > 0.98 and free_gib > 7.5:
  66. N_MAX = 1<<18
  67. M_MAX = 24
  68. elif epc_gib > 0.9 and free_gib > 4.2:
  69. N_MAX = 1<<17
  70. M_MAX = 48
  71. else:
  72. print(f"""
  73. *** You have too small EPC ({epc_gib:.2f} GiB) and/or free
  74. *** memory ({free_gib:.2f} GiB) to run TEEMS, even with
  75. *** SHRINK_TO_MEM set to 1
  76. """)
  77. sys.exit(1)
  78. ## Figure 7 ID channel
  79. TOKEN_CHANNEL = False
  80. N = [n for n in [1<<15, 1<<16, 1<<17, 1<<18, 1<<19, 1<<20] if n <= N_MAX]
  81. M = [4]
  82. T = [4]
  83. run_exp(LOG_FOLDER, TOKEN_CHANNEL, NUM_EPOCHS, N, M, T, B, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)
  84. ## Figure 8 ID channel
  85. TOKEN_CHANNEL = False
  86. N = [N_MAX]
  87. M = [m for m in [72, 64, 48, 44, 40, 36, 32, 24, 20, 16, 8, 6, 4] if m <= M_MAX]
  88. T = [1]
  89. run_exp(LOG_FOLDER, TOKEN_CHANNEL, NUM_EPOCHS, N, M, T, B, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)
  90. ## Figure 7 Token channel
  91. TOKEN_CHANNEL = True
  92. N = [n for n in [1<<15, 1<<16, 1<<17, 1<<18, 1<<19, 1<<20] if n <= N_MAX]
  93. M = [4]
  94. T = [4]
  95. run_exp(LOG_FOLDER, TOKEN_CHANNEL, NUM_EPOCHS, N, M, T, B, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)
  96. ## Figure 8 Token channel
  97. TOKEN_CHANNEL = True
  98. N = [N_MAX]
  99. M = [m for m in [72, 64, 48, 44, 40, 36, 32, 24, 20, 16, 8, 6, 4] if m <= M_MAX]
  100. T = [1]
  101. run_exp(LOG_FOLDER, TOKEN_CHANNEL, NUM_EPOCHS, N, M, T, B, TOKEN_OUT, TOKEN_IN, ID_OUT, ID_IN)