Skip to content

Commit dda5969

Browse files
committed
Update wrk benchmarks: Add a wait_until_live
1 parent 446d35e commit dda5969

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

benchmarks/starlette_benchmark.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22
import subprocess
33
import sys
44
import time
5+
import requests
56

67
def generate_wrk_command_for_url(url):
78
# Define the command with awk included
89
return "wrk -t5 -c200 -d15s " + url
910

11+
def wait_until_live(url):
12+
for i in range(30):
13+
try:
14+
res = requests.get(url, timeout=5)
15+
if res.status_code == 200:
16+
print("Server is live: " + url)
17+
return True
18+
else:
19+
print("Status code " + str(res.status_code) + " for " + url)
20+
except requests.RequestException as e:
21+
print(f"Request failed: {e}")
22+
time.sleep(5)
23+
return False
24+
25+
1026
def extract_requests_and_latency_tuple(output):
1127
if output.returncode == 0:
1228
# Extracting requests/sec
@@ -23,6 +39,11 @@ def extract_requests_and_latency_tuple(output):
2339
sys.exit(1)
2440

2541
def run_benchmark(route1, route2, descriptor, percentage_limit):
42+
# Make sure both routes are accessible before running benchmark
43+
if not wait_until_live(route1):
44+
raise Exception("Unable to access: " + route1)
45+
if not wait_until_live(route2):
46+
raise Exception("Unable to access: " + route2)
2647

2748
output_nofw = subprocess.run(
2849
generate_wrk_command_for_url(route2),

0 commit comments

Comments
 (0)