setup_mysql.py 856 B

123456789101112131415161718192021222324252627
  1. import subprocess
  2. import os
  3. def start(args, logfile, errfile):
  4. conn_string = ('dbname=hello_world '
  5. 'user=benchmarkdbuser '
  6. 'password=benchmarkdbpass '
  7. 'host=' + args.database_host)
  8. subprocess.check_call("urweb -dbms mysql -db \"" + conn_string + "\" bench", shell=True, cwd="urweb", stderr=errfile, stdout=logfile)
  9. threads = str(args.max_threads * 2)
  10. subprocess.Popen("./bench.exe -q -k -t " + threads,
  11. shell=True, cwd="urweb", stderr=errfile, stdout=logfile)
  12. return 0
  13. def stop(logfile, errfile):
  14. p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
  15. out, err = p.communicate()
  16. for line in out.splitlines():
  17. if 'bench.exe' in line:
  18. try:
  19. pid = int(line.split(None, 2)[1])
  20. os.kill(pid, 9)
  21. except OSError:
  22. pass
  23. return 0