-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·37 lines (30 loc) · 1.02 KB
/
benchmark.sh
File metadata and controls
executable file
·37 lines (30 loc) · 1.02 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
#!/bin/bash
# benchmark.sh - Multithreaded HTTP/HTTPS benchmark script
# Usage: benchmark.sh <threads> <requests_per_thread> <port> <protocol> <path>
if [ $# -ne 5 ]; then
echo "Usage: $0 <threads> <requests_per_thread> <port> <protocol> <path>"
exit 1
fi
threads=$1
requests_per_thread=$2
port=$3
protocol=$4
path=$5
set -m # Enable job control
thread_pids=""
# Start worker threads using coproc
for i in $(seq 1 $threads); do
if [ "$protocol" = "https" ]; then
coproc bash -c "for j in \$(seq 1 $requests_per_thread); do curl -k -s https://localhost:$port$path > /dev/null 2>&1; done"
else
coproc bash -c "for j in \$(seq 1 $requests_per_thread); do echo -e 'GET $path HTTP/1.1\\nHost: localhost:$port\\n\\n' | nc -w 1 localhost $port > /dev/null 2>&1; done"
fi
thread_pids="$thread_pids $COPROC_PID"
# Close file descriptors to avoid warnings
exec {COPROC[0]}<&-
exec {COPROC[1]}>&-
done
# Wait for all threads to complete
for pid in $thread_pids; do
wait $pid 2>/dev/null
done