-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadTest.py
31 lines (25 loc) · 905 Bytes
/
LoadTest.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
import requests, time, asyncio
from concurrent.futures import ThreadPoolExecutor, wait
from uuid import uuid4
def get_site(uid, n):
prevId = ""
visited = set()
for _ in range(n):
resp = requests.post("http://127.0.0.1:8000/getSite", json={"userId": uid, "prevId": prevId})
j = resp.json()
if j["siteId"] in visited:
print(f"Repeat on {j['siteId']}")
visited.add(j["siteId"])
#print(j["siteId"], prevId)
prevId = resp.json()["siteId"]
return resp
N = 16
while N < 128:
result = []
start_time = time.time()
with ThreadPoolExecutor(max_workers=40) as tpe:
futures = [tpe.submit(get_site, f"loadtest{str(uuid4())}", 100) for _ in range(N)]
done, not_done = wait(futures, timeout=None)
print(len(done), len(not_done))
print(f"{time.time() - start_time}, {N * 100}")
N = N * 2