From 4e57fd96f8fe7c37dd7be93a60e0d5a7b0aec860 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Wed, 22 Oct 2025 08:25:54 +0200 Subject: [PATCH] Add more parameters and wait for server availability --- scripts/stress.sh | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/scripts/stress.sh b/scripts/stress.sh index 5e1364e..938595b 100755 --- a/scripts/stress.sh +++ b/scripts/stress.sh @@ -1,14 +1,43 @@ #!/bin/bash -thisdir=`dirname "$0"` +thisdir=$(dirname "$0") + +WRK_SETTINGS="--timeout 2s --threads 2 --connections 10 --duration 30s --rate 200" +JVM_PARAMS="-XX:ActiveProcessorCount=8 -Xms512m -Xmx512m" +WAIT_SERVER=${WAIT_SERVER:-true} + +# if no jar is provided as argument, exit and complain +if [ "$#" -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi # make sure the port is clear before enabling halting-on-error -kill $(lsof -t -i:8080) &>/dev/null +kill $(lsof -t -i:8080) &>/dev/null || true set -euo pipefail ${thisdir}/infra.sh -s -java -XX:ActiveProcessorCount=8 -Xms512m -Xmx512m -jar $1 & -jbang wrk2@hyperfoil -t2 -c100 -d30s -R 200 --latency http://localhost:8080/fruits -scripts/infra.sh -d -kill $(lsof -t -i:8080) &>/dev/null \ No newline at end of file +java ${JVM_PARAMS} -jar $1 & + +if [ "$WAIT_SERVER" = "true" ]; then +echo "Waiting for server to be ready..." +# wait until any HTTP response is received (connect succeeds) +until curl -sS http://localhost:8080 >/dev/null 2>&1; do + sleep 0.5 +done +fi + +echo "-----------------------------------------" +echo "Starting wrk2" +echo "-----------------------------------------" + +jbang wrk2@hyperfoil ${WRK_SETTINGS} http://localhost:8080/fruits + +echo "-----------------------------------------" +echo "Stopped wrk2" +echo "-----------------------------------------" + +# Kill the Java process (listening on 8080) +kill -TERM $(lsof -t -i:8080) &>/dev/null || true +${thisdir}/infra.sh -d