test.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import time
  4. import sys
  5. def next_client(clients):
  6. if len(clients) == 0:
  7. return
  8. c = clients.pop()
  9. args = ["./random_client.py", str(c)]
  10. proc = subprocess.Popen(args, stderr=subprocess.DEVNULL)
  11. proc.cid = c
  12. return proc
  13. def run_clients(max_clients):
  14. clients = list(range(1, max_clients))
  15. start_time = time.time()
  16. running_clients = []
  17. while True:
  18. print(len(running_clients))
  19. if len(running_clients) < max_clients:
  20. c = next_client(clients)
  21. if c is not None:
  22. running_clients.append(c)
  23. else:
  24. time.sleep(0.1)
  25. for c in running_clients:
  26. c.poll()
  27. if c.returncode is not None:
  28. running_clients.remove(c)
  29. clients.append(c.cid)
  30. c.terminate()
  31. c.wait()
  32. env = {}
  33. env["LD_LIBRARY_PATH"] = "../../lib"
  34. #broker = subprocess.Popen(["../../src/mosquitto", "-c", "random.conf"], env=env)
  35. run_clients(1000)