run-tests.py 6.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python
  2. import argparse
  3. import ConfigParser
  4. import sys
  5. import os
  6. from pprint import pprint
  7. from benchmark.benchmarker import Benchmarker
  8. from setup.linux.unbuffered import Unbuffered
  9. ###################################################################################################
  10. # Main
  11. ###################################################################################################
  12. def main(argv=None):
  13. # Do argv default this way, as doing it in the functional declaration sets it at compile time
  14. if argv is None:
  15. argv = sys.argv
  16. # Enable unbuffered output so messages will appear in the proper order with subprocess output.
  17. sys.stdout=Unbuffered(sys.stdout)
  18. # Ensure the current directory (which should be the benchmark home directory) is in the path so that the tests can be imported.
  19. sys.path.append('.')
  20. # Ensure toolset/setup/linux is in the path so that the tests can "import setup_util".
  21. sys.path.append('toolset/setup/linux')
  22. conf_parser = argparse.ArgumentParser(
  23. description=__doc__,
  24. formatter_class=argparse.RawDescriptionHelpFormatter,
  25. add_help=False)
  26. conf_parser.add_argument('--conf_file', default='benchmark.cfg', metavar='FILE', help='Optional configuration file to provide argument defaults. All config options can be overridden using the command line.')
  27. args, remaining_argv = conf_parser.parse_known_args()
  28. try:
  29. with open (args.conf_file):
  30. config = ConfigParser.SafeConfigParser()
  31. config.read([os.getcwd() + '/' + args.conf_file])
  32. defaults = dict(config.items("Defaults"))
  33. except IOError:
  34. if args.conf_file != 'benchmark.cfg':
  35. print 'Configuration file not found!'
  36. defaults = { "client-host":"localhost"}
  37. ##########################################################
  38. # Set up argument parser
  39. ##########################################################
  40. parser = argparse.ArgumentParser(description='Run the Framework Benchmarking test suite.',
  41. parents=[conf_parser])
  42. parser.add_argument('-s', '--server-host', default='localhost', help='The application server.')
  43. parser.add_argument('-c', '--client-host', default='localhost', help='The client / load generation server.')
  44. parser.add_argument('-u', '--client-user', help='The username to use for SSH to the client instance.')
  45. parser.add_argument('-i', '--client-identity-file', dest='client_identity_file', help='The key to use for SSH to the client instance.')
  46. parser.add_argument('-d', '--database-host', help='The database server. If not provided, defaults to the value of --client-host.')
  47. parser.add_argument('--database-user', help='The username to use for SSH to the database instance. If not provided, defaults to the value of --client-user.')
  48. parser.add_argument('--database-identity-file', dest='database_identity_file', help='The key to use for SSH to the database instance. If not provided, defaults to the value of --client-identity-file.')
  49. parser.add_argument('-p', dest='password_prompt', action='store_true')
  50. parser.add_argument('--install-software', action='store_true', help='runs the installation script before running the rest of the commands')
  51. parser.add_argument('--install', choices=['client', 'database', 'server', 'all'], default='all', help='Allows you to only install the server, client, or database software')
  52. parser.add_argument('--install-error-action', choices=['abort', 'continue'], default='continue', help='action to take in case of error during installation')
  53. parser.add_argument('--test', nargs='+', help='names of tests to run')
  54. parser.add_argument('--exclude', nargs='+', help='names of tests to exclude')
  55. parser.add_argument('--type', choices=['all', 'json', 'db', 'query', 'fortune', 'update', 'plaintext'], default='all', help='which type of test to run')
  56. parser.add_argument('-m', '--mode', choices=['benchmark', 'verify'], default='benchmark', help='verify mode will only start up the tests, curl the urls and shutdown')
  57. parser.add_argument('--list-tests', action='store_true', default=False, help='lists all the known tests that can run')
  58. parser.add_argument('--list-test-metadata', action='store_true', default=False, help='writes all the test metadata as a JSON file in the results directory')
  59. parser.add_argument('--max-concurrency', default=256, help='the maximum concurrency that the tests will run at. The query tests will run at this concurrency', type=int)
  60. parser.add_argument('--max-queries', default=20, help='The maximum number of queries to run during the query test', type=int)
  61. parser.add_argument('--query-interval', default=5, type=int)
  62. parser.add_argument('--max-threads', default=8, help='The max number of threads to run weight at, this should be set to the number of cores for your system.', type=int)
  63. parser.add_argument('--duration', default=60, help='Time in seconds that each test should run for.')
  64. parser.add_argument('--starting-concurrency', default=8, type=int)
  65. parser.add_argument('--sleep', type=int, default=60, help='the amount of time to sleep after starting each test to allow the server to start up.')
  66. parser.add_argument('--parse', help='Parses the results of the given timestamp and merges that with the latest results')
  67. parser.add_argument('--name', default="ec2", help='The name to give this test. Results will be placed in a folder using this name.')
  68. parser.add_argument('--os', choices=['linux', 'windows'], default='linux', help='The operating system of the application server.')
  69. parser.add_argument('--database-os', choices=['linux', 'windows'], default='linux', help='The operating system of the database server.')
  70. parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Causes the configuration to print before any other commands are executed.')
  71. parser.set_defaults(**defaults) # Must do this after add, or each option's default will override the configuration file default
  72. args = parser.parse_args(remaining_argv)
  73. if args.verbose:
  74. print 'Configuration options: '
  75. pprint(args)
  76. benchmarker = Benchmarker(vars(args))
  77. # Run the benchmarker in the specified mode
  78. if benchmarker.list_tests:
  79. benchmarker.run_list_tests()
  80. elif benchmarker.list_test_metadata:
  81. benchmarker.run_list_test_metadata()
  82. elif benchmarker.parse != None:
  83. benchmarker.parse_timestamp()
  84. else:
  85. benchmarker.run()
  86. if __name__ == "__main__":
  87. sys.exit(main())