-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.py
More file actions
49 lines (38 loc) · 1.47 KB
/
sync.py
File metadata and controls
49 lines (38 loc) · 1.47 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
import os
import requests
import tempfile
import time
from lib import generate_valid_urls, get_dir_name
from runner import program_runner
def main(url_count=50):
failed_count = 0
total_bytes = 0
with tempfile.NamedTemporaryFile(mode="ab+", delete=True) as f:
with requests.Session() as s:
for url in generate_valid_urls(url_count):
try:
response = s.get(url=url)
except Exception as e:
print(e)
failed_count += 1
continue
else:
if not response.ok:
print(response.status_code)
failed_count += 1
continue
f.write(response.content)
f.flush()
total_bytes = os.stat(f.name).st_size
return total_bytes, failed_count
if __name__ == "__main__":
for count in [100, 1000]:
print("Execution for", count,"urls...")
program_runner(
main,
f"sync_data_with_{count}_urls",
get_dir_name(__file__),
url_count=count,
descr=f"""Io bound execution using sync programming. The experiment fetches {count} urls and stores the response data into a file. The returned values represent the total bytes received from network and the number of failed requests (>=400 status code or error)."""
)
time.sleep(5)