#!/usr/bin/env bash # Runs each approach against the huge file under a ladder of -Xmx limits, one fresh JVM per run. # Streaming modes run every rung (to show memory stays flat). Tree/bind climb until the first # rung that succeeds, then stop. Output: output/bench.txt (timings vary run to run) set -u cd "$(dirname "$0")/.." FILE="${1:-target/huge.json}" CP="target/classes:$(cat target/cp.txt)" OUT=output/bench.txt mkdir -p output { echo "file: $FILE ($(stat -c %s "$FILE") bytes)" echo "java: $(java -version 2>&1 | grep -v 'Picked up' | head -1)" echo "cpus: $(nproc) ram: $(free -m | awk '/Mem:/{print $2}') MB" echo for mode in stream hybrid; do for x in 32 64 128 1024; do java -Xmx${x}m -cp "$CP" com.ankurm.jackson3.streaminghuge.Scan $mode "$FILE" 2>&1 | grep -v '^Picked up' done done for mode in tree bind; do for x in 64 256 1024 2048 3072 4096 6144; do line=$(timeout 900 java -Xmx${x}m -cp "$CP" com.ankurm.jackson3.streaminghuge.Scan $mode "$FILE" 2>&1 | grep -v '^Picked up'; echo "exit=${PIPESTATUS[0]}") # no output at all = the JVM was SIGKILLed (exit 137) by the container's OOM killer case "$line" in exit=*) line=$(printf '%-7s -Xmx=%5d MB KILLED no Java output, %s (SIGKILL by the OS: the heap limit was larger than free RAM)' "$mode" "$x" "$line");; *) line="${line%exit=*}"; line="${line%$'\n'}";; esac echo "$line" case "$line" in *" OK "*) break;; esac done done } | tee "$OUT"