-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeadOfLineBlockingTest.py
48 lines (37 loc) · 1.53 KB
/
HeadOfLineBlockingTest.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
import argparse
import time
import aiohttp
import asyncio
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
import hashlib
from time import sleep
parser = argparse.ArgumentParser(prog='Get');
parser.add_argument('url1')
parser.add_argument('url2')
parser.add_argument('-d', '--delay', default=100)
args = parser.parse_args()
dataFrame = pandas.DataFrame(columns=['url', 'byteSize', 'duration'])
async def get(url, session):
async with session.get(url) as response:
start = time.time()
result = await response.read()
duration = time.time() - start
return {'url': url, 'byteSize': len(result), 'duration': duration, 'datarate': ((len(result) / 1000000) / duration), 'sha1sum': hashlib.sha1(result).hexdigest()}
async def main():
async with aiohttp.ClientSession() as session:
tasks = []
url = args.url1
tasks.append(asyncio.ensure_future(get(url, session)))
sleep(args.delay / 1000)
url = args.url2
tasks.append(asyncio.ensure_future(get(url, session)))
results = await asyncio.gather(*tasks)
for result in results:
print(result['url'] + ': Get ' + str(result['byteSize']) + ' bytes in ' + str(result['duration']) + ' seconds. (' + str(result['datarate']) + ' MB/s)')
global dataFrame
dataFrame = pandas.concat([dataFrame, pandas.DataFrame.from_records([result])], ignore_index=True)
asyncio.run(main())
print(dataFrame.to_string())
print("Overall data rate: " + str(dataFrame['datarate'].sum()))