blob: 7354b80d30db1b5f5aa87fd8f160c04d9434a550 [file] [log] [blame]
Jonathan Harta061cc52013-04-30 10:41:21 -07001#!/usr/bin/env python
2
3"""
4Small script to run a stress test on a Cassandra cluster.
5The script will periodically query data from Cassandra via ONOS
6and time the request duration.
7"""
8
9import os
10import sys
11import json
12import time
13import timeit
Jonathan Hartdc502122013-05-04 21:18:01 -070014from datetime import datetime
Jonathan Harta061cc52013-04-30 10:41:21 -070015
16host = "localhost"
17port = "9000"
18
19url="http://%s:%s/wm/core/topology/switches/all/json" % (host, port)
20command = "curl -m 5 -s %s" % url
21
22if len(sys.argv) < 2:
23 print "usage: %s output_file" % sys.argv[0]
24 sys.exit(1)
25
26output_filename = sys.argv[1]
27output_file = open(output_filename, 'w')
28output_file.write("Time" + os.linesep)
29
30def do_request():
31 try:
32 result = os.popen(command).read()
33 parsedResult = json.loads(result)
Jonathan Hartdc502122013-05-04 21:18:01 -070034 return True
Jonathan Harta061cc52013-04-30 10:41:21 -070035 except Exception as e:
Jonathan Hartdc502122013-05-04 21:18:01 -070036 print "Curl call failed at %s: %s" % (datetime.now(), e)
37 return False
Jonathan Harta061cc52013-04-30 10:41:21 -070038
Jonathan Harta061cc52013-04-30 10:41:21 -070039if __name__ == "__main__":
40 while (True):
Jonathan Hartdc502122013-05-04 21:18:01 -070041 #time_elapsed = timeit.timeit('do_request()', 'from __main__ import do_request, last_call_successful', number=1)
42 start_time = time.time()
43 result = do_request()
44 end_time = time.time()
45
46 if result:
47 output_file.write("%s%s" % (end_time - start_time, os.linesep))
48 else:
49 output_file.write("%s%s" % (0, os.linesep))
50
Jonathan Harta061cc52013-04-30 10:41:21 -070051 output_file.flush()
52 time.sleep(1)