-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstampeding-herd.py
56 lines (47 loc) · 1.47 KB
/
stampeding-herd.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
import concurrent.futures
import os
import random
import time
from collections import defaultdict
import requests
def _get_size(url):
sleep = random.random() / 10
# print("sleep", sleep)
time.sleep(sleep)
r = requests.get(url)
# print(r.status_code)
if not r.text:
print(
"EMPTY TEXT!!",
"File exists?",
os.path.isfile(
"./peterbecom-static-content/_FSCACHE/plog/blogitem-040601-1/index.html"
),
"Size?",
os.stat(
"./peterbecom-static-content/_FSCACHE/plog/blogitem-040601-1/index.html"
).st_size,
"X-Local?",
repr(r.headers["x-local"]),
)
assert len(r.text), r.headers["x-local"]
return len(r.text), r.headers["x-local"]
def run(url, times=100):
sizes = []
futures = []
with concurrent.futures.ThreadPoolExecutor() as executor:
for _ in range(times):
futures.append(executor.submit(_get_size, url))
for future in concurrent.futures.as_completed(futures):
sizes.append(future.result())
print(sizes)
if sizes:
count_x_locals = defaultdict(int)
for _, x_local in sizes:
count_x_locals[x_local] += 1
for key, count in count_x_locals.items():
print(key, "{:.1f}%".format(100 * count / sum(count_x_locals.values())))
return 0
if __name__ == "__main__":
import sys
sys.exit(run(sys.argv[1]))