Repository navigation
Expand file tree
/
Copy pathbench_concurrent.sh
More file actions
55 lines (44 loc) · 1.5 KB
/
Copy pathbench_concurrent.sh
File metadata and controls
55 lines (44 loc) · 1.5 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
#!/bin/bash
# Binary search for maximum stable concurrent connections with QPS output
# Usage: ./max_concurrency_binary.sh http://127.0.0.1:8080 4 1000 65535
# Arguments:
# $1 = Test URL
# $2 = wrk thread count
# $3 = Minimum connections to start
# $4 = Maximum connections to test
URL=${1:-http://127.0.0.1:8080}
THREADS=${2:-4}
MIN_CONN=${3:-1000}
MAX_CONN=${4:-65535}
ulimit -n $MAX_CONN
LAST_OK_CONN=$MIN_CONN
LOW=$MIN_CONN
HIGH=$MAX_CONN
MAX_ITER=20
ITER=0
while (( LOW <= HIGH && ITER < MAX_ITER ))
do
((ITER++))
MID=$(( (LOW + HIGH) / 2 ))
echo "Testing concurrency: $MID"
# Run wrk for 10 seconds to speed up binary search
OUTPUT=$(wrk -t$THREADS -c$MID -d10s $URL 2>&1)
# Extract the number of connect errors (robust sed, works on macOS and Linux)
CONN_ERR=$(printf "%s" "$OUTPUT" | sed -En 's/.*Socket errors: connect[[:space:]]+([0-9]+).*/\1/p')
CONN_ERR=${CONN_ERR:-0}
# Extract Requests/sec (robust sed)
REQ_PER_SEC=$(printf "%s" "$OUTPUT" | sed -En 's/.*Requests\/sec:[[:space:]]*([0-9]+(\.[0-9]+)?).*/\1/p')
REQ_PER_SEC=${REQ_PER_SEC:-0}
echo "Connect errors: $CONN_ERR, QPS: $REQ_PER_SEC"
# Consider connection stable if errors <= 1% of MID
THRESHOLD=$(( MID / 100 ))
if (( CONN_ERR <= THRESHOLD )); then
# Stable, try higher concurrency
LAST_OK_CONN=$MID
LOW=$(( MID + 1 ))
else
# Unstable, reduce concurrency
HIGH=$(( MID - 1 ))
fi
done
echo "Maximum stable concurrent connections: $LAST_OK_CONN"