-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
27 lines (23 loc) · 991 Bytes
/
benchmark.py
File metadata and controls
27 lines (23 loc) · 991 Bytes
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
def send_query():
headers = {
"Host": "www.llama.leonliang.lu"
}
url = "http://localhost:8080/health"
start_total = time.time()
for i in range(10):
try:
start = time.time()
response = requests.get(url, headers=headers)
response.raise_for_status()
duration = time.time() - start
total_duration = time.time() - start_total
print(f"Request succeeded on attempt {i+1} in {duration:.3f}s, total elapsed {total_duration:.3f}s")
return response.json(), total_duration
except requests.exceptions.RequestException as e:
print(f"[Attempt {i+1}] Request failed: {e}")
time.sleep(0.5)
total_duration = time.time() - start_total
raise Exception(f"Service did not become ready after 10 retries. Total elapsed: {total_duration:.3f}s")
response, duration = send_query()
print(f"Duration: {duration:.3f} seconds")
print("Response:", response)