run-tests.py 7.2 KB

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