-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.py
More file actions
41 lines (28 loc) · 1.08 KB
/
lib.py
File metadata and controls
41 lines (28 loc) · 1.08 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
import resource
import os
from pathlib import Path
def generate_valid_urls(count=10000):
param = "abcdefghijklmnopqrstuvwxyz"
base_url = os.getenv("BENCH_SERVER_URL", None)
if base_url == None:
raise Exception(
f"Please provide the httpbin server base url as env variable to the process with key: BENCH_SERVER_URL"
)
for i in range(count):
url = f"http://{base_url}/anything/{i}?query={param}"
if len(param.encode()) // 1000 >= 1:
param = "abcdefghijklmnopqrstuvwxyz"
else:
param += param
yield url
def get_dir_name(path_str:str):
return Path(path_str).parent.name
def get_openable_fd_for_req():
openable, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
return 1000 if openable > 1024 else 500
def raise_fd_limit(count=2048):
_, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
new_soft = min(count, hard)
resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, hard))
new_soft, _ = resource.getrlimit(resource.RLIMIT_NOFILE)
return new_soft >= count