clientlaunch 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python3
  2. import argparse
  3. import os
  4. import shlex
  5. import subprocess
  6. import sys
  7. import threading
  8. import yaml
  9. sys.path.insert(0, os.getcwd())
  10. sys.path.insert(1, './../App/')
  11. import mkconfig
  12. # The default manifest file
  13. MANIFEST = "./../App/manifest.yaml"
  14. # The default pubkeys file
  15. PUBKEYS = "./../App/pubkeys.yaml"
  16. # The client binary
  17. CLIENTS = "./clients"
  18. # Client thread allocation
  19. prefix = "numactl -C36-39,76-79 "
  20. def launch(config, cmd, threads, ip_start, lgfile):
  21. cmdline = ''
  22. cmdline += prefix + CLIENTS + " -t " + str(threads) + ""
  23. stdout_file = subprocess.PIPE
  24. if(lgfile):
  25. stdout_file = open(lgfile, "a+")
  26. proc = subprocess.Popen(shlex.split(cmdline) + cmd,
  27. stdin=subprocess.PIPE, stdout=stdout_file,
  28. stderr=subprocess.STDOUT, bufsize=0)
  29. print(cmdline)
  30. proc.stdin.write(config.encode('utf-8'))
  31. if(lgfile):
  32. proc.wait()
  33. stdout_file.close()
  34. else:
  35. while True:
  36. line = proc.stdout.readline()
  37. if not line:
  38. break
  39. print(line.decode('utf-8'), end='', flush=True)
  40. if __name__ == "__main__":
  41. print("In clientlaunch")
  42. aparse = argparse.ArgumentParser(
  43. description='Launch CLIENTS'
  44. )
  45. aparse.add_argument('-m', default=MANIFEST,
  46. help='manifest.yaml file')
  47. aparse.add_argument('-p', default=PUBKEYS,
  48. help='pubkeys.yaml file')
  49. aparse.add_argument('-t', default=1,
  50. help='number of threads')
  51. aparse.add_argument('-z', default=None,
  52. help='override message size')
  53. aparse.add_argument('-u', default=None,
  54. help='override max number of users')
  55. aparse.add_argument('-B', default=None,
  56. help='override max number of outgoing private messages per user per epoch')
  57. aparse.add_argument('-b', default=None,
  58. help='override max number of incoming private messages per user per epoch')
  59. aparse.add_argument('-C', default=None,
  60. help='override max number of outgoing public messages per user per epoch')
  61. aparse.add_argument('-c', default=None,
  62. help='override max number of incoming public messages per user per epoch')
  63. aparse.add_argument('-l', default=None,
  64. help='log file to store client simulator log for an experiment')
  65. aparse.add_argument('-n', nargs='*', help='nodes to include')
  66. aparse.add_argument('cmd', nargs='*', help='experiment to run')
  67. args = aparse.parse_args()
  68. with open(args.m) as mf:
  69. manifest = yaml.safe_load(mf)
  70. params_overrides = {
  71. 'msg_size': args.z,
  72. 'user_count': args.u,
  73. 'priv_out': args.B,
  74. 'priv_in': args.b,
  75. 'pub_out': args.C,
  76. 'pub_in': args.c,
  77. }
  78. config = mkconfig.create_json(args.m, args.p, args.n, params_overrides)
  79. # There must not be any newlines in the config json string
  80. if "\n" in config:
  81. print("Error: config.json must not contain embedded newlines")
  82. sys.exit(1)
  83. # Now add a trailing newline
  84. config += "\n"
  85. launch(config, args.cmd, args.t, args.q, args.l)