-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_futures.py
30 lines (25 loc) · 956 Bytes
/
socket_futures.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
#!/usr/bin/env python3
import os
import concurrent.futures
from time import time
from utils import load_csv, get_url
def main(endpoints):
results = []
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = {executor.submit(get_url, endpoint): endpoint for endpoint in endpoints}
for future in concurrent.futures.as_completed(futures):
endpoint = futures[future]
try:
results.append(future.result())
except Exception as exc:
print('%r generated an exception: %s' % (endpoint, exc))
return results
if __name__ == '__main__':
top_sites = f'{os.path.dirname(os.path.realpath(__file__))}/top-1m.csv'
endpoints = load_csv(top_sites)
site_chunk = [10, 100, 500, 1000]
for n in site_chunk:
start = time()
results = main(endpoints[0:n])
end = time()
print(f"{n} endpoints took {end-start:.2f} seconds")