benchmarker.py 30 KB

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