#!/usr/bin/env bash # Find the minimum viable -Xmx for a single match, at two match sizes. # # This is the number the hosting bill is built on. Under process-per-match, cost # is (peak RSS per match JVM) x (peak concurrent matches), so guessing here # propagates straight into the cost model. # # Success criteria: the JVM survives and the game reaches the target round. A run # that OOMs, or that limps without advancing, is a failure at that heap size. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OUT="$ROOT/results/sweep" mkdir -p "$OUT" SETTLE=4 MAXROUND=9 MAXSEC=240 run_one() { local label="$1" scenario="$2" heap="$3" local csv="$OUT/${label}-${heap}.csv" local log="$OUT/${label}-${heap}.log" MM_JAR="$ROOT/MegaMek-patched.jar" HEAP="$heap" timeout $((MAXSEC + 90)) \ "$ROOT/harness/run.sh" --games 1 --scenario "$scenario" \ --settle-round "$SETTLE" --max-rounds "$MAXROUND" --max-seconds "$MAXSEC" \ --csv "$csv" > "$log" 2>&1 || true local oom peak round status oom=$(grep -c "OutOfMemoryError" "$log" || true) if [ -s "$csv" ]; then peak=$(awk -F, 'NR>1 && $6>m {m=$6} END{printf "%.0f", m/1024}' "$csv") round=$(awk -F, 'NR>1 {r=$5} END{print r+0}' "$csv") else peak=0; round=0 fi if [ "$oom" -gt 0 ]; then status="OOM" elif [ "$round" -lt "$SETTLE" ]; then status="STALLED(r=$round)" else status="ok(r=$round)" fi printf "%-10s %-6s peakRSS=%5s MB %s\n" "$label" "$heap" "$peak" "$status" } echo "=== 4v4 (BrokenArrow, 8 units) ===" for h in 384m 512m 768m 1g 2g; do run_one 4v4 "data/scenarios/BrokenArrow.mms" "$h" done echo echo "=== 2v2 (FirstRun, 4 units) ===" for h in 384m 512m 768m 1g; do run_one 2v2 "data/scenarios/TrainingScenarios/1-FirstRun.mms" "$h" done