Skip to content

Commit c8d5d8e

Browse files
committed
Add more parameters and wait for server availability
1 parent 41601ec commit c8d5d8e

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

scripts/stress.sh

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,43 @@
11
#!/bin/bash
22

3-
thisdir=`dirname "$0"`
3+
thisdir=$(dirname "$0")
4+
5+
WRK_SETTINGS="--timeout 2s --threads 2 --connections 10 --duration 30s --rate 200"
6+
JVM_PARAMS="-XX:ActiveProcessorCount=8 -Xms512m -Xmx512m"
7+
WAIT_SERVER=${WAIT_SERVER:-true}
8+
9+
# if no jar is provided as argument, exit and complain
10+
if [ "$#" -eq 0 ]; then
11+
echo "Usage: $0 <path-to-jar>"
12+
exit 1
13+
fi
414

515
# make sure the port is clear before enabling halting-on-error
6-
kill $(lsof -t -i:8080) &>/dev/null
16+
kill $(lsof -t -i:8080) &>/dev/null || true
717

818
set -euo pipefail
919

1020
${thisdir}/infra.sh -s
11-
java -XX:ActiveProcessorCount=8 -Xms512m -Xmx512m -jar $1 &
12-
jbang wrk2@hyperfoil -t2 -c100 -d30s -R 200 --latency http://localhost:8080/fruits
13-
scripts/infra.sh -d
14-
kill $(lsof -t -i:8080) &>/dev/null
21+
java ${JVM_PARAMS} -jar $1 &
22+
23+
if [ "$WAIT_SERVER" = "true" ]; then
24+
echo "Waiting for server to be ready..."
25+
# wait until any HTTP response is received (connect succeeds)
26+
until curl -sS http://localhost:8080 >/dev/null 2>&1; do
27+
sleep 0.5
28+
done
29+
fi
30+
31+
echo "-----------------------------------------"
32+
echo "Starting wrk2"
33+
echo "-----------------------------------------"
34+
35+
jbang wrk2@hyperfoil ${WRK_SETTINGS} http://localhost:8080/fruits
36+
37+
echo "-----------------------------------------"
38+
echo "Stopped wrk2"
39+
echo "-----------------------------------------"
40+
41+
# Kill the Java process (listening on 8080)
42+
kill -TERM $(lsof -t -i:8080) &>/dev/null || true
43+
${thisdir}/infra.sh -d

0 commit comments

Comments
 (0)