Skip to content

Commit 24e781c

Browse files
committed
Update wrk benchmarks
1 parent dda5969 commit 24e781c

6 files changed

Lines changed: 54 additions & 20 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ jobs:
6262
run: |
6363
k6 run -q ./benchmarks/flask-mysql-benchmarks.js
6464
65-
benchmark_with_starlette_app:
65+
wrk_benchmarks:
6666
runs-on: ubuntu-latest
6767
timeout-minutes: 10
6868
strategy:
6969
fail-fast: false
7070
matrix:
71+
app: [starlette-postgres-uvicorn, flask-mysql-uwsgi]
7172
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
7273
steps:
7374
- name: Checkout code
@@ -83,12 +84,13 @@ jobs:
8384
run: |
8485
python -m pip install --upgrade pip
8586
make install && make build
86-
- name: Start starlette
87-
working-directory: ./sample-apps/starlette-postgres-uvicorn
87+
- name: Start app
88+
working-directory: ./sample-apps/${{ matrix.app }}
8889
run: nohup make runBenchmark & nohup make runZenDisabled &
8990
- name: Install wrk
9091
run: |
9192
sudo apt-get update
9293
sudo apt-get install -y wrk
93-
- name: Run benchmark
94-
run: python ./benchmarks/starlette_benchmark.py
94+
- name: Run benchmarks
95+
working-directory: ./benchmarks/wrk_benchmark
96+
run: make benchmark_${{ matrix.app }}

benchmarks/wrk_benchmark/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
.PHONY: benchmark_starlette-postgres-uvicorn
3+
benchmark_starlette-postgres-uvicorn:
4+
@echo "Running wrk benchmarks for Starlette w/ Postgres, Uvicorn"
5+
python starlette_postgres_uvicorn.py
6+
7+
.PHONY: benchmark_flask-mysql-uwsgi
8+
benchmark_flask-mysql-uwsgi:
9+
@echo "Running wrk benchmarks for Flask w/ MySQL, UWSGI"
10+
python flask_mysql_uwsgi.py
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from script import run_benchmark
2+
3+
# Run benchmarks
4+
5+
run_benchmark(
6+
"http://localhost:8088/benchmark",
7+
"http://localhost:8089/benchmark",
8+
"a non empty route which makes a simulated request to a database",
9+
percentage_limit=15
10+
)
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def generate_wrk_command_for_url(url):
88
# Define the command with awk included
9-
return "wrk -t5 -c200 -d15s " + url
9+
return "wrk -t12 -c400 -d15s " + url
1010

1111
def wait_until_live(url):
1212
for i in range(30):
@@ -34,12 +34,12 @@ def extract_requests_and_latency_tuple(output):
3434
latency_float *= 1000
3535
return (float(requests_sec), latency_float)
3636
else:
37-
print("Exception occurred running benchmark command:")
37+
print("Error occured running benchmark command:")
3838
print(output.stderr.strip())
3939
sys.exit(1)
4040

4141
def run_benchmark(route1, route2, descriptor, percentage_limit):
42-
# Make sure both routes are accessible before running benchmark
42+
# Cold start :
4343
if not wait_until_live(route1):
4444
raise Exception("Unable to access: " + route1)
4545
if not wait_until_live(route2):
@@ -72,23 +72,13 @@ def run_benchmark(route1, route2, descriptor, percentage_limit):
7272

7373
delta_in_ms = round(result_fw[1] - result_nofw[1], 2)
7474
print(f"-> Delta in ms: {delta_in_ms}ms after running load test on {descriptor}")
75+
7576
delay_percentage = round(
7677
(result_nofw[0] - result_fw[0]) / result_nofw[0] * 100
7778
)
7879
print(
7980
f"-> {delay_percentage}% decrease in throughput after running load test on {descriptor} \n"
8081
)
82+
8183
if delay_percentage > percentage_limit:
8284
sys.exit(1)
83-
84-
# Run benchmarks :
85-
run_benchmark(
86-
"http://localhost:8102/delayed_route",
87-
"http://localhost:8103/delayed_route",
88-
"a non empty route which makes a simulated request to a database",
89-
percentage_limit=15
90-
)
91-
run_benchmark(
92-
"http://localhost:8102/just", "http://localhost:8103/just", "an empty route",
93-
percentage_limit=30
94-
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from script import run_benchmark
2+
3+
# Run benchmarks
4+
5+
run_benchmark(
6+
"http://localhost:8102/delayed_route",
7+
"http://localhost:8103/delayed_route",
8+
"a non empty route which makes a simulated request to a database",
9+
percentage_limit=15
10+
)
11+
12+
run_benchmark(
13+
"http://localhost:8102/just", "http://localhost:8103/just", "an empty route",
14+
percentage_limit=30
15+
)

sample-apps/flask-mysql-uwsgi/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import aikido_zen # Aikido package import
24
aikido_zen.protect()
35

@@ -44,3 +46,8 @@ def create_dog():
4446
cursor.execute(f'INSERT INTO dogs (dog_name, isAdmin) VALUES ("%s", 0)' % (dog_name))
4547
connection.commit()
4648
return f'Dog {dog_name} created successfully'
49+
50+
@app.route("/benchmark", methods=['GET'])
51+
def benchmark():
52+
time.sleep(1)
53+
return "OK"

0 commit comments

Comments
 (0)