#!/usr/bin/env bash # A slow client against a fast model: curl reads 300 KB/s of a 600 x 32 KB stream (19.6 MB) while the # stub writes with no delay. Samples how far the stub got and how much heap the app holds. # Usage: backpressure.sh [extra app args] source "$(dirname "$0")/lib.sh"; set +e MODE=${1:-none}; shift stop_all; start_stub 0; start_app --chat.backpressure="$MODE" --chat.slow-millis=5 "$@" echo "== chat.backpressure=$MODE (stub delay 0 ms, 600 chunks x 32 KiB, client reads 64 KiB every 0.2 s)" echo 0 > "$RUN/recv.bytes" python3 scripts/slow_client.py "http://localhost:$APP_PORT/chat/stream?message=big%20600&turn=1" "$RUN/recv.bytes" & CURL=$! T0=$(date +%s.%N) for pause in 1 1 2 3 4; do sleep "$pause" st=$(curl -s "localhost:$STUB_PORT/stub/stats" | sed 's/requests=[0-9]* //') recv=$(cat "$RUN/recv.bytes") now=$(date +%s.%N) jcmd "$(cat $RUN/app.pid)" GC.run >/dev/null 2>&1 heap=$(jcmd "$(cat $RUN/app.pid)" GC.heap_info 2>/dev/null | grep -o "used [0-9]*K" | head -1) printf "t=%4.1fs client got %5d KiB stub: %s app heap after GC: %s\n" "$(echo "$now - $T0" | bc)" $((recv/1024)) "$st" "$heap" done wait $CURL 2>/dev/null echo "-- app log (demand + outcome):" grep "demand\|CANCELLED\|complete\|error" $RUN/app.log | sed "s/turn 1 //" | sort | uniq -c | sort -rn | head -6 stop_all