-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·70 lines (59 loc) · 1.65 KB
/
benchmark.sh
File metadata and controls
executable file
·70 lines (59 loc) · 1.65 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
BASEURL='http://localhost:3000'
CONCURRENT_REQUESTS=100
# Kills wrt background process on script early exit
trap "exit" INT TERM
trap "kill 0" EXIT
# Usage:
# benchmark.sh worker
# benchmark.sh single
# benchmark.sh --help
# Handle arguments
if [ "$1" == "worker" ]; then
MODE="worker"
elif [ "$1" == "single" ]; then
MODE="single"
elif [ "$1" == "--help" ]; then
echo "Usage:"
echo "benchmark.sh worker"
echo "benchmark.sh single"
echo "benchmark.sh --help"
exit 0
else
echo "Invalid argument. Use 'worker', 'single', or '--help'."
exit 1
fi
# Check if server is running
response=$(curl -s -o /dev/null --max-time 1 -w "%{http_code}" "$BASEURL")
# Allow 200 or 404 as valid responses
if [ "$response" -ne 200 ] && [ "$response" -ne 404 ]; then
echo "Error: Server at $BASEURL took too long to respond. Have we started the server? (pnpm start)?"
exit 1
fi
# Functions for benchmark tests
parallel_api_call_sim() {
# Sends an GET request to /hello with a 1 sec timeout
time curl "$BASEURL/hello" --max-time 1 --silent --show-error --max-time 1 --fail -o /dev/null
if [ $? -eq 0 ]; then
echo "Parallel Curl $BASEURL/hello succeeded!"
else
echo "Parallel Curl $BASEURL/hello failed. This means server has performance issues"
fi
}
run_worker_test() {
wrk -t12 "-c$CONCURRENT_REQUESTS" -d10s "$BASEURL/prime/worker" &
sleep 2s;
parallel_api_call_sim
}
run_single_test() {
wrk -t12 "-c$CONCURRENT_REQUESTS" -d10s "$BASEURL/prime/single" &
sleep 2s;
parallel_api_call_sim
}
# Execute the selected test
if [ "$MODE" == "worker" ]; then
run_worker_test
elif [ "$MODE" == "single" ]; then
run_single_test
fi
sleep 2s