benchmarker.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. from setup.linux.installer import Installer
  2. from benchmark import framework_test
  3. import os
  4. import json
  5. import subprocess
  6. import time
  7. import textwrap
  8. import pprint
  9. import csv
  10. import sys
  11. import logging
  12. from multiprocessing import Process
  13. from datetime import datetime
  14. class Benchmarker:
  15. ##########################################################################################
  16. # Public methods
  17. ##########################################################################################
  18. ############################################################
  19. # Prints all the available tests
  20. ############################################################
  21. def run_list_tests(self):
  22. all_tests = self.__gather_tests
  23. for test in all_tests:
  24. print test.name
  25. self.__finish()
  26. ############################################################
  27. # End run_list_tests
  28. ############################################################
  29. ############################################################
  30. # Prints the metadata for all the available tests
  31. ############################################################
  32. def run_list_test_metadata(self):
  33. all_tests = self.__gather_tests
  34. all_tests_json = json.dumps(map(lambda test: {
  35. "name": test.name,
  36. "approach": test.approach,
  37. "classification": test.classification,
  38. "database": test.database,
  39. "framework": test.framework,
  40. "language": test.language,
  41. "orm": test.orm,
  42. "platform": test.platform,
  43. "webserver": test.webserver,
  44. "os": test.os,
  45. "database_os": test.database_os,
  46. "display_name": test.display_name,
  47. "notes": test.notes,
  48. "versus": test.versus
  49. }, all_tests))
  50. with open(os.path.join(self.full_results_directory(), "test_metadata.json"), "w") as f:
  51. f.write(all_tests_json)
  52. self.__finish()
  53. ############################################################
  54. # End run_list_test_metadata
  55. ############################################################
  56. ############################################################
  57. # parse_timestamp
  58. # Re-parses the raw data for a given timestamp
  59. ############################################################
  60. def parse_timestamp(self):
  61. all_tests = self.__gather_tests
  62. for test in all_tests:
  63. test.parse_all()
  64. self.__parse_results(all_tests)
  65. self.__finish()
  66. ############################################################
  67. # End parse_timestamp
  68. ############################################################
  69. ############################################################
  70. # Run the tests:
  71. # This process involves setting up the client/server machines
  72. # with any necessary change. Then going through each test,
  73. # running their setup script, verifying the URLs, and
  74. # running benchmarks against them.
  75. ############################################################
  76. def run(self):
  77. ##########################
  78. # Get a list of all known
  79. # tests that we can run.
  80. ##########################
  81. all_tests = self.__gather_tests
  82. ##########################
  83. # Setup client/server
  84. ##########################
  85. print textwrap.dedent("""
  86. =====================================================
  87. Preparing Server, Database, and Client ...
  88. =====================================================
  89. """)
  90. self.__setup_server()
  91. self.__setup_database()
  92. self.__setup_client()
  93. ##########################
  94. # Run tests
  95. ##########################
  96. self.__run_tests(all_tests)
  97. ##########################
  98. # Parse results
  99. ##########################
  100. if self.mode == "benchmark":
  101. print textwrap.dedent("""
  102. =====================================================
  103. Parsing Results ...
  104. =====================================================
  105. """)
  106. self.__parse_results(all_tests)
  107. self.__finish()
  108. ############################################################
  109. # End run
  110. ############################################################
  111. ############################################################
  112. # database_sftp_string(batch_file)
  113. # generates a fully qualified URL for sftp to database
  114. ############################################################
  115. def database_sftp_string(self, batch_file):
  116. sftp_string = "sftp -oStrictHostKeyChecking=no "
  117. if batch_file != None: sftp_string += " -b " + batch_file + " "
  118. if self.database_identity_file != None:
  119. sftp_string += " -i " + self.database_identity_file + " "
  120. return sftp_string + self.database_user + "@" + self.database_host
  121. ############################################################
  122. # End database_sftp_string
  123. ############################################################
  124. ############################################################
  125. # client_sftp_string(batch_file)
  126. # generates a fully qualified URL for sftp to client
  127. ############################################################
  128. def client_sftp_string(self, batch_file):
  129. sftp_string = "sftp -oStrictHostKeyChecking=no "
  130. if batch_file != None: sftp_string += " -b " + batch_file + " "
  131. if self.client_identity_file != None:
  132. sftp_string += " -i " + self.client_identity_file + " "
  133. return sftp_string + self.client_user + "@" + self.client_host
  134. ############################################################
  135. # End client_sftp_string
  136. ############################################################
  137. ############################################################
  138. # generate_url(url, port)
  139. # generates a fully qualified URL for accessing a test url
  140. ############################################################
  141. def generate_url(self, url, port):
  142. return self.server_host + ":" + str(port) + url
  143. ############################################################
  144. # End generate_url
  145. ############################################################
  146. ############################################################
  147. # output_file(test_name, test_type)
  148. # returns the output file for this test_name and test_type
  149. # timestamp/test_type/test_name/raw
  150. ############################################################
  151. def output_file(self, test_name, test_type):
  152. path = os.path.join(self.result_directory, self.timestamp, test_type, test_name, "raw")
  153. try:
  154. os.makedirs(os.path.dirname(path))
  155. except OSError:
  156. pass
  157. return path
  158. ############################################################
  159. # End output_file
  160. ############################################################
  161. ############################################################
  162. # full_results_directory
  163. ############################################################
  164. def full_results_directory(self):
  165. path = os.path.join(self.result_directory, self.timestamp)
  166. try:
  167. os.makedirs(path)
  168. except OSError:
  169. pass
  170. return path
  171. ############################################################
  172. # End output_file
  173. ############################################################
  174. ############################################################
  175. # Latest intermediate results dirctory
  176. ############################################################
  177. def latest_results_directory(self):
  178. path = os.path.join(self.result_directory,"latest")
  179. try:
  180. os.makedirs(path)
  181. except OSError:
  182. pass
  183. return path
  184. ############################################################
  185. # report_results
  186. ############################################################
  187. def report_results(self, framework, test, results):
  188. if test not in self.results['rawData'].keys():
  189. self.results['rawData'][test] = dict()
  190. self.results['rawData'][test][framework.name] = results
  191. ############################################################
  192. # End report_results
  193. ############################################################
  194. ##########################################################################################
  195. # Private methods
  196. ##########################################################################################
  197. ############################################################
  198. # Gathers all the tests
  199. ############################################################
  200. @property
  201. def __gather_tests(self):
  202. tests = []
  203. # Loop through each directory (we assume we're being run from the benchmarking root)
  204. # and look for the files that signify a benchmark test
  205. for dirname, dirnames, filenames in os.walk('.'):
  206. # Look for the benchmark_config file, this will set up our tests.
  207. # Its format looks like this:
  208. #
  209. # {
  210. # "framework": "nodejs",
  211. # "tests": [{
  212. # "default": {
  213. # "setup_file": "setup",
  214. # "json_url": "/json"
  215. # },
  216. # "mysql": {
  217. # "setup_file": "setup",
  218. # "db_url": "/mysql",
  219. # "query_url": "/mysql?queries="
  220. # },
  221. # ...
  222. # }]
  223. # }
  224. if 'benchmark_config' in filenames:
  225. config = None
  226. config_file_name = os.path.join(dirname, 'benchmark_config')
  227. with open(config_file_name, 'r') as config_file:
  228. # Load json file into config object
  229. try:
  230. config = json.load(config_file)
  231. except:
  232. print("Error loading '%s'." % config_file_name)
  233. raise
  234. if config == None:
  235. continue
  236. tests = tests + framework_test.parse_config(config, dirname[2:], self)
  237. tests.sort(key=lambda x: x.name)
  238. return tests
  239. ############################################################
  240. # End __gather_tests
  241. ############################################################
  242. ############################################################
  243. # Gathers all the frameworks
  244. ############################################################
  245. def __gather_frameworks(self):
  246. frameworks = []
  247. # Loop through each directory (we assume we're being run from the benchmarking root)
  248. for dirname, dirnames, filenames in os.walk('.'):
  249. # Look for the benchmark_config file, this will contain our framework name
  250. # It's format looks like this:
  251. #
  252. # {
  253. # "framework": "nodejs",
  254. # "tests": [{
  255. # "default": {
  256. # "setup_file": "setup",
  257. # "json_url": "/json"
  258. # },
  259. # "mysql": {
  260. # "setup_file": "setup",
  261. # "db_url": "/mysql",
  262. # "query_url": "/mysql?queries="
  263. # },
  264. # ...
  265. # }]
  266. # }
  267. if 'benchmark_config' in filenames:
  268. config = None
  269. with open(os.path.join(dirname, 'benchmark_config'), 'r') as config_file:
  270. # Load json file into config object
  271. config = json.load(config_file)
  272. if config == None:
  273. continue
  274. frameworks.append(str(config['framework']))
  275. return frameworks
  276. ############################################################
  277. # End __gather_frameworks
  278. ############################################################
  279. ############################################################
  280. # Makes any necessary changes to the server that should be
  281. # made before running the tests. This involves setting kernal
  282. # settings to allow for more connections, or more file
  283. # descriptiors
  284. #
  285. # http://redmine.lighttpd.net/projects/weighttp/wiki#Troubleshooting
  286. ############################################################
  287. def __setup_server(self):
  288. try:
  289. if os.name == 'nt':
  290. return True
  291. subprocess.check_call(["sudo","bash","-c","cd /sys/devices/system/cpu; ls -d cpu*|while read x; do echo performance > $x/cpufreq/scaling_governor; done"])
  292. subprocess.check_call("sudo sysctl -w net.core.somaxconn=5000".rsplit(" "))
  293. subprocess.check_call("sudo -s ulimit -n 16384".rsplit(" "))
  294. subprocess.check_call("sudo sysctl net.ipv4.tcp_tw_reuse=1".rsplit(" "))
  295. subprocess.check_call("sudo sysctl net.ipv4.tcp_tw_recycle=1".rsplit(" "))
  296. subprocess.check_call("sudo sysctl -w kernel.shmmax=134217728".rsplit(" "))
  297. subprocess.check_call("sudo sysctl -w kernel.shmall=2097152".rsplit(" "))
  298. except subprocess.CalledProcessError:
  299. return False
  300. ############################################################
  301. # End __setup_server
  302. ############################################################
  303. ############################################################
  304. # Makes any necessary changes to the database machine that
  305. # should be made before running the tests. Is very similar
  306. # to the server setup, but may also include database specific
  307. # changes.
  308. ############################################################
  309. def __setup_database(self):
  310. p = subprocess.Popen(self.database_ssh_string, stdin=subprocess.PIPE, shell=True)
  311. p.communicate("""
  312. sudo sysctl -w net.core.somaxconn=5000
  313. sudo -s ulimit -n 16384
  314. sudo sysctl net.ipv4.tcp_tw_reuse=1
  315. sudo sysctl net.ipv4.tcp_tw_recycle=1
  316. sudo sysctl -w kernel.shmmax=2147483648
  317. sudo sysctl -w kernel.shmall=2097152
  318. """)
  319. ############################################################
  320. # End __setup_database
  321. ############################################################
  322. ############################################################
  323. # Makes any necessary changes to the client machine that
  324. # should be made before running the tests. Is very similar
  325. # to the server setup, but may also include client specific
  326. # changes.
  327. ############################################################
  328. def __setup_client(self):
  329. p = subprocess.Popen(self.client_ssh_string, stdin=subprocess.PIPE, shell=True)
  330. p.communicate("""
  331. sudo sysctl -w net.core.somaxconn=5000
  332. sudo -s ulimit -n 16384
  333. sudo sysctl net.ipv4.tcp_tw_reuse=1
  334. sudo sysctl net.ipv4.tcp_tw_recycle=1
  335. sudo sysctl -w kernel.shmmax=2147483648
  336. sudo sysctl -w kernel.shmall=2097152
  337. """)
  338. ############################################################
  339. # End __setup_client
  340. ############################################################
  341. ############################################################
  342. # __run_tests
  343. #
  344. # 2013-10-02 ASB Calls each test passed in tests to
  345. # __run_test in a separate process. Each
  346. # test is given a set amount of time and if
  347. # kills the child process (and subsequently
  348. # all of its child processes). Uses
  349. # multiprocessing module.
  350. ############################################################
  351. def __run_tests(self, tests):
  352. logging.debug("Start __run_tests.")
  353. for test in tests:
  354. logging.debug("Creating child process for %s",test.name)
  355. if __name__ == '__main__':
  356. test_process = Process(target=f, args=(test,))
  357. logging.debug("Starting child process for %s",test.name)
  358. test_process.start()
  359. test_process.join(self.run_test_timeout_seconds)
  360. logging.debug("Child process for %s joined parent")
  361. if(test_process.is_alive()):
  362. logging.debug("Child process for %s is still alive. Terminating.",test.name)
  363. write_intermediate_results(test.name,"__run_test timeout (="+ str(self.run_test_timeout_seconds) + " seconds)")
  364. test_process.terminate()
  365. logging.debug("End __run_tests.")
  366. ############################################################
  367. # End __run_tests
  368. ############################################################
  369. ############################################################
  370. # __run_test
  371. # 2013-10-02 ASB Previously __run_tests. This code now only
  372. # processes a single test.
  373. #
  374. # Ensures that the system has all necessary software to run
  375. # the tests. This does not include that software for the individual
  376. # test, but covers software such as curl and weighttp that
  377. # are needed.
  378. ############################################################
  379. def __run_test(self, test):
  380. logging.debug("Start __run_test for: %s",test.name)
  381. if test.os.lower() != self.os.lower() or test.database_os.lower() != self.database_os.lower():
  382. # the operating system requirements of this test for the
  383. # application server or the database server don't match
  384. # our current environment
  385. return
  386. # If the user specified which tests to run, then
  387. # we can skip over tests that are not in that list
  388. if self.test != None and test.name not in self.test:
  389. return
  390. # If the test is in the excludes list, we skip it
  391. if self.exclude != None and test.name in self.exclude:
  392. return
  393. # If the test does not contain an implementation of the current test-type, skip it
  394. if self.type != 'all' and not test.contains_type(self.type):
  395. return
  396. logging.debug("self.results['frameworks'] != None: " + str(self.results['frameworks'] != None))
  397. logging.debug("test.name: " + str(test.name))
  398. logging.debug("self.results['completed']: " + str(self.results['completed']))
  399. if self.results['frameworks'] != None and test.name in self.results['completed']:
  400. logging.info('Framework %s found in latest saved data. Skipping.',str(test.name))
  401. return
  402. print textwrap.dedent("""
  403. =====================================================
  404. Beginning {name}
  405. -----------------------------------------------------
  406. """.format(name=test.name))
  407. ##########################
  408. # Start this test
  409. ##########################
  410. print textwrap.dedent("""
  411. -----------------------------------------------------
  412. Starting {name}
  413. -----------------------------------------------------
  414. """.format(name=test.name))
  415. try:
  416. p = subprocess.Popen(self.database_ssh_string, stdin=subprocess.PIPE, shell=True)
  417. p.communicate("""
  418. sudo restart mysql
  419. sudo restart mongodb
  420. sudo /etc/init.d/postgresql restart
  421. """)
  422. time.sleep(10)
  423. result = test.start()
  424. if result != 0:
  425. test.stop()
  426. time.sleep(5)
  427. print "ERROR: Problem starting " + test.name
  428. print textwrap.dedent("""
  429. -----------------------------------------------------
  430. Stopped {name}
  431. -----------------------------------------------------
  432. """.format(name=test.name))
  433. self.__write_intermediate_results(test.name,"<setup.py>#start() returned non-zero")
  434. return
  435. time.sleep(self.sleep)
  436. ##########################
  437. # Verify URLs
  438. ##########################
  439. print textwrap.dedent("""
  440. -----------------------------------------------------
  441. Verifying URLs for {name}
  442. -----------------------------------------------------
  443. """.format(name=test.name))
  444. test.verify_urls()
  445. ##########################
  446. # Benchmark this test
  447. ##########################
  448. if self.mode == "benchmark":
  449. print textwrap.dedent("""
  450. -----------------------------------------------------
  451. Benchmarking {name} ...
  452. -----------------------------------------------------
  453. """.format(name=test.name))
  454. test.benchmark()
  455. ##########################
  456. # Stop this test
  457. ##########################
  458. test.stop()
  459. time.sleep(5)
  460. print textwrap.dedent("""
  461. -----------------------------------------------------
  462. Stopped {name}
  463. -----------------------------------------------------
  464. """.format(name=test.name))
  465. time.sleep(5)
  466. ##########################################################
  467. # Save results thus far into toolset/benchmark/latest.json
  468. ##########################################################
  469. print textwrap.dedent("""
  470. ----------------------------------------------------
  471. Saving results through {name}
  472. ----------------------------------------------------
  473. )""".format(name=test.name))
  474. self.__write_intermediate_results(test.name,time.strftime("%Y%m%d%H%M%S", time.localtime()))
  475. except (OSError, subprocess.CalledProcessError):
  476. self.__write_intermediate_results(test.name,"<setup.py> raised an exception")
  477. print textwrap.dedent("""
  478. -----------------------------------------------------
  479. Subprocess Error {name}
  480. -----------------------------------------------------
  481. """.format(name=test.name))
  482. try:
  483. test.stop()
  484. except (subprocess.CalledProcessError):
  485. self.__write_intermediate_results(test.name,"<setup.py>#stop() raised an error")
  486. print textwrap.dedent("""
  487. -----------------------------------------------------
  488. Subprocess Error: Test .stop() raised exception {name}
  489. -----------------------------------------------------
  490. """.format(name=test.name))
  491. except (KeyboardInterrupt, SystemExit):
  492. test.stop()
  493. print """
  494. -----------------------------------------------------
  495. Cleaning up....
  496. -----------------------------------------------------
  497. """
  498. self.__finish()
  499. sys.exit()
  500. ############################################################
  501. # End __run_tests
  502. ############################################################
  503. ############################################################
  504. # __parse_results
  505. # Ensures that the system has all necessary software to run
  506. # the tests. This does not include that software for the individual
  507. # test, but covers software such as curl and weighttp that
  508. # are needed.
  509. ############################################################
  510. def __parse_results(self, tests):
  511. # Run the method to get the commmit count of each framework.
  512. self.__count_commits()
  513. # Call the method which counts the sloc for each framework
  514. self.__count_sloc()
  515. # Time to create parsed files
  516. # Aggregate JSON file
  517. with open(os.path.join(self.full_results_directory(), "results.json"), "w") as f:
  518. f.write(json.dumps(self.results))
  519. ############################################################
  520. # End __parse_results
  521. ############################################################
  522. #############################################################
  523. # __count_sloc
  524. # This is assumed to be run from the benchmark root directory
  525. #############################################################
  526. def __count_sloc(self):
  527. all_frameworks = self.__gather_frameworks()
  528. jsonResult = {}
  529. for framework in all_frameworks:
  530. try:
  531. command = "cloc --list-file=" + framework['directory'] + "/source_code --yaml"
  532. lineCount = subprocess.check_output(command, shell=True)
  533. # Find the last instance of the word 'code' in the yaml output. This should
  534. # be the line count for the sum of all listed files or just the line count
  535. # for the last file in the case where there's only one file listed.
  536. lineCount = lineCount[lineCount.rfind('code'):len(lineCount)]
  537. lineCount = lineCount.strip('code: ')
  538. lineCount = lineCount[0:lineCount.rfind('comment')]
  539. jsonResult[framework['name']] = int(lineCount)
  540. except:
  541. continue
  542. self.results['rawData']['slocCounts'] = jsonResult
  543. ############################################################
  544. # End __count_sloc
  545. ############################################################
  546. ############################################################
  547. # __count_commits
  548. ############################################################
  549. def __count_commits(self):
  550. all_frameworks = self.__gather_frameworks()
  551. jsonResult = {}
  552. for framework in all_frameworks:
  553. try:
  554. command = "git rev-list HEAD -- " + framework + " | sort -u | wc -l"
  555. commitCount = subprocess.check_output(command, shell=True)
  556. jsonResult[framework] = int(commitCount)
  557. except:
  558. continue
  559. self.results['rawData']['commitCounts'] = jsonResult
  560. self.commits = jsonResult
  561. ############################################################
  562. # End __count_commits
  563. ############################################################
  564. ############################################################
  565. # __write_intermediate_results
  566. ############################################################
  567. def __write_intermediate_results(self,test_name,status_message):
  568. try:
  569. self.results["completed"][test_name] = status_message
  570. with open(os.path.join(self.latest_results_directory, 'results.json'), 'w') as f:
  571. f.write(json.dumps(self.results))
  572. except (IOError):
  573. logging.error("Error writing results.json")
  574. ############################################################
  575. # End __write_intermediate_results
  576. ############################################################
  577. ############################################################
  578. # __finish
  579. ############################################################
  580. def __finish(self):
  581. print "Time to complete: " + str(int(time.time() - self.start_time)) + " seconds"
  582. print "Results are saved in " + os.path.join(self.result_directory, self.timestamp)
  583. ############################################################
  584. # End __finish
  585. ############################################################
  586. ##########################################################################################
  587. # Constructor
  588. ##########################################################################################
  589. ############################################################
  590. # Initialize the benchmarker. The args are the arguments
  591. # parsed via argparser.
  592. ############################################################
  593. def __init__(self, args):
  594. self.run_test_timeout_seconds = 60
  595. self.__dict__.update(args)
  596. self.start_time = time.time()
  597. # setup logging
  598. logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
  599. # setup some additional variables
  600. if self.database_user == None: self.database_user = self.client_user
  601. if self.database_host == None: self.database_host = self.client_host
  602. if self.database_identity_file == None: self.database_identity_file = self.client_identity_file
  603. # setup results and latest_results directories
  604. self.result_directory = os.path.join("results", self.name)
  605. self.latest_results_directory = self.latest_results_directory()
  606. if self.parse != None:
  607. self.timestamp = self.parse
  608. else:
  609. self.timestamp = time.strftime("%Y%m%d%H%M%S", time.localtime())
  610. # Setup the concurrency levels array. This array goes from
  611. # starting_concurrency to max concurrency, doubling each time
  612. self.concurrency_levels = []
  613. concurrency = self.starting_concurrency
  614. while concurrency <= self.max_concurrency:
  615. self.concurrency_levels.append(concurrency)
  616. concurrency = concurrency * 2
  617. # Setup query interval array
  618. # starts at 1, and goes up to max_queries, using the query_interval
  619. self.query_intervals = []
  620. queries = 1
  621. while queries <= self.max_queries:
  622. self.query_intervals.append(queries)
  623. if queries == 1:
  624. queries = 0
  625. queries = queries + self.query_interval
  626. # Load the latest data
  627. #self.latest = None
  628. #try:
  629. # with open('toolset/benchmark/latest.json', 'r') as f:
  630. # # Load json file into config object
  631. # self.latest = json.load(f)
  632. # logging.info("toolset/benchmark/latest.json loaded to self.latest")
  633. # logging.debug("contents of latest.json: " + str(json.dumps(self.latest)))
  634. #except IOError:
  635. # logging.warn("IOError on attempting to read toolset/benchmark/latest.json")
  636. #
  637. #self.results = None
  638. #try:
  639. # if self.latest != None and self.name in self.latest.keys():
  640. # with open(os.path.join(self.result_directory, str(self.latest[self.name]), 'results.json'), 'r') as f:
  641. # # Load json file into config object
  642. # self.results = json.load(f)
  643. #except IOError:
  644. # pass
  645. self.results = None
  646. try:
  647. with open(os.path.join(self.latest_results_directory, 'results.json'), 'r') as f:
  648. #Load json file into results object
  649. self.results = json.load(f)
  650. except IOError:
  651. logging.warn("results.json for test %s not found.",self.name)
  652. if self.results == None:
  653. self.results = dict()
  654. self.results['name'] = self.name
  655. self.results['concurrencyLevels'] = self.concurrency_levels
  656. self.results['queryIntervals'] = self.query_intervals
  657. self.results['frameworks'] = [t.name for t in self.__gather_tests]
  658. self.results['duration'] = self.duration
  659. self.results['rawData'] = dict()
  660. self.results['rawData']['json'] = dict()
  661. self.results['rawData']['db'] = dict()
  662. self.results['rawData']['query'] = dict()
  663. self.results['rawData']['fortune'] = dict()
  664. self.results['rawData']['update'] = dict()
  665. self.results['rawData']['plainteat'] = dict()
  666. self.results['completed'] = dict()
  667. else:
  668. #for x in self.__gather_tests():
  669. # if x.name not in self.results['frameworks']:
  670. # self.results['frameworks'] = self.results['frameworks'] + [x.name]
  671. # Always overwrite framework list
  672. self.results['frameworks'] = [t.name for t in self.__gather_tests]
  673. # Setup the ssh command string
  674. self.database_ssh_string = "ssh -T -o StrictHostKeyChecking=no " + self.database_user + "@" + self.database_host
  675. self.client_ssh_string = "ssh -T -o StrictHostKeyChecking=no " + self.client_user + "@" + self.client_host
  676. if self.database_identity_file != None:
  677. self.database_ssh_string = self.database_ssh_string + " -i " + self.database_identity_file
  678. if self.client_identity_file != None:
  679. self.client_ssh_string = self.client_ssh_string + " -i " + self.client_identity_file
  680. if self.install_software:
  681. install = Installer(self)
  682. install.install_software()
  683. ############################################################
  684. # End __init__
  685. ############################################################