-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest-timer.py
More file actions
executable file
·54 lines (42 loc) · 1.25 KB
/
Copy pathrequest-timer.py
File metadata and controls
executable file
·54 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/python
import sys
import json
import httplib
import time
def readJson(path):
fin = open(path)
data = json.load(fin)
fin.close()
return data
def getCurrentMilliseconds():
return int(time.time() * 1000.0)
def request(options):
startTime = getCurrentMilliseconds()
conn = httplib.HTTPConnection(options['host'])
conn.request(options['method'].upper(), options['uri'], options['body'], options['headers'])
response = conn.getresponse()
endTime = getCurrentMilliseconds()
timeTaken = endTime - startTime
print 'After ' + str(timeTaken) + ' ms: [' + str(response.status) + '] ' + response.reason
return timeTaken
argc = len(sys.argv)
if (argc == 0):
print 'This script requires one argument - config file path.'
elif (argc > 2):
print 'Too many arguments.'
else:
path = sys.argv[1]
print 'Loading config file \"' + path + '\"'
config = readJson(path)
print 'Requesting http://' + config['host'] + config['uri']
timeSum = 0
timeCount = 0
for i in range(0, config['count']):
timeTaken = request(config)
if (timeTaken > 0):
timeCount += 1
timeSum += timeTaken
else:
print 'Request failed.'
print str(timeCount) + ' out of ' + str(config['count']) + ' request succeeded.'
print 'Average request time: ' + str(timeSum / timeCount)