-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSlowStart.py
81 lines (64 loc) · 2.87 KB
/
TestSlowStart.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import argparse
import time
import statistics
import urllib.request
import urllib.response
import urllib.error
import ssl
import functools
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
import hashlib
parser = argparse.ArgumentParser(prog='Get');
parser.add_argument('url')
args = parser.parse_args()
dataFrame = pandas.DataFrame(columns=['url', 'byteSize', 'duration'])
ssssl = ssl.create_default_context()
ssssl.check_hostname = False
ssssl.verify_mode = ssl.CERT_NONE
#first request
try:
start = time.time()
response = urllib.request.urlopen(args.url, context=ssssl)
data = response.read()
duration = time.time() - start
print('Get ' + args.url + ' in ' + str(duration) + ' (' + str((len(data) / 1000000) / duration) + ' MB/s)')
dataFrame = pandas.concat([dataFrame, pandas.DataFrame.from_records([{'url': args.url, 'byteSize': len(data), 'duration': duration, 'datarate': (len(data) / 1000000) / duration, 'sha1sum': hashlib.sha1(data).hexdigest()}])], ignore_index=True)
except urllib.error.HTTPError as e:
print("HTTPError: {}".format(e.code))
except urllib.error.URLError as e:
print('URLError: {}'.format(e.reason))
#second request right after the first one
try:
start = time.time()
response = urllib.request.urlopen(args.url, context=ssssl)
data = response.read()
duration = time.time() - start
print('Get ' + args.url + ' in ' + str(duration) + ' (' + str((len(data) / 1000000) / duration) + ' MB/s)')
dataFrame = pandas.concat([dataFrame, pandas.DataFrame.from_records([{'url': args.url, 'byteSize': len(data), 'duration': duration, 'datarate': (len(data) / 1000000) / duration, 'sha1sum': hashlib.sha1(data).hexdigest()}])], ignore_index=True)
except urllib.error.HTTPError as e:
print("HTTPError: {}".format(e.code))
except urllib.error.URLError as e:
print('URLError: {}'.format(e.reason))
#third request 10s delayed
time.sleep(10)
try:
start = time.time()
response = urllib.request.urlopen(args.url, context=ssssl)
data = response.read()
duration = time.time() - start
print('Get ' + args.url + ' in ' + str(duration) + ' (' + str((len(data) / 1000000) / duration) + ' MB/s)')
dataFrame = pandas.concat([dataFrame, pandas.DataFrame.from_records([{'url': args.url, 'byteSize': len(data), 'duration': duration, 'datarate': (len(data) / 1000000) / duration, 'sha1sum': hashlib.sha1(data).hexdigest()}])], ignore_index=True)
except urllib.error.HTTPError as e:
print("HTTPError: {}".format(e.code))
except urllib.error.URLError as e:
print('URLError: {}'.format(e.reason))
print(dataFrame.to_string())
fig, (ax1, ax2) = plt.subplots(2, 1, sharey=False)
fig.suptitle("Parallel GET " + args.url)
sns.barplot(ax=ax1, data=dataFrame, x=dataFrame.index, y="duration")
ax1.set_title("duration")
sns.barplot(ax=ax2, data=dataFrame, x=dataFrame.index, y="datarate")
ax2.set_title("datarate")
plt.show()