#!/usr/bin/env bash # Regenerates every file in ../output/. Requires JDK25_HOME. Needs ~5.3 GB of free disk in $DATA (default /tmp/nio2-data); # the generated files are deleted on exit. Set BIG_BYTES to use a smaller "big" file (default 5 GB). set -euo pipefail [[ -z "${JDK25_HOME:-}" ]] && { echo "JDK25_HOME must be set" >&2; exit 1; } cd "$(dirname "$0")/.." OUT=output; mkdir -p "$OUT" DATA="${DATA:-/tmp/nio2-data}"; mkdir -p "$DATA" BIG_BYTES="${BIG_BYTES:-5000000000}" MED_BYTES=200000000 trap 'rm -rf "$DATA"' EXIT export JAVA_HOME="$JDK25_HOME" mvn -q -f ../pom.xml -pl nio2 -am package J="$JDK25_HOME/bin/java"; CP=target/classes strip() { grep -v "Picked up"; } { echo '$ uname -sr'; uname -sr; echo '$ nproc'; nproc; echo '$ java -version'; "$J" -version 2>&1 | strip echo '$ ulimit -n'; ulimit -n echo '$ cat /proc/sys/fs/inotify/max_queued_events'; cat /proc/sys/fs/inotify/max_queued_events echo '$ df -h (data directory, before)'; df -h "$DATA" | sed 's/ */ /g'; } > "$OUT/01-environment.txt" echo "==> generate files" { "$J" -cp $CP com.ankurm.nio2.LogFile "$DATA/big.log" "$BIG_BYTES" 2>&1 | strip "$J" -cp $CP com.ankurm.nio2.LogFile "$DATA/medium.log" "$MED_BYTES" 2>&1 | strip echo '$ ls -l (generated files)'; ls -l "$DATA"/*.log | awk '{print $5, $9}' | sed "s#$DATA/##" echo '$ df -h (data directory, with both files on disk)'; df -h "$DATA" | sed 's/ */ /g'; } > "$OUT/02-generate.txt" echo "==> stream the big file at -Xmx64m" for m in lines reader; do n=$([[ $m == lines ]] && echo 03 || echo 04) { echo "\$ java -Xmx64m -Xlog:gc StreamLines $m big.log" "$J" -Xmx64m -Xlog:gc:file="$DATA/gc-$m.log" -cp $CP com.ankurm.nio2.StreamLines $m "$DATA/big.log" 2>&1 | strip echo "GC log: $(wc -l < "$DATA/gc-$m.log") lines, $(grep -c 'Pause Young' "$DATA/gc-$m.log") young pauses, $(grep -c 'Pause Full' "$DATA/gc-$m.log") full GCs" echo "first lines of the GC log:"; head -4 "$DATA/gc-$m.log" | cut -c1-150 echo "last lines of the GC log:"; tail -3 "$DATA/gc-$m.log" | cut -c1-150 echo "largest 'Pause Young' (ms): $(grep 'Pause Young' "$DATA/gc-$m.log" | sed 's/.* \([0-9.]*\)ms$/\1/' | sort -n | tail -1)" echo "highest heap-after-GC seen in the log: $(grep 'Pause Young' "$DATA/gc-$m.log" | sed 's/.*->\([0-9]*\)M(.*/\1/' | sort -n | tail -1)M of $(grep -m1 'Pause Young' "$DATA/gc-$m.log" | sed 's/.*M(\([0-9]*\)M).*/\1/')M"; } > "$OUT/$n-stream-$m.txt" done echo "==> readAllLines / readString / readAllBytes" { for f in medium big; do for m in readAllLines readString readAllBytes; do echo "\$ java -Xmx64m ReadAllFail $m $f.log"; "$J" -Xmx64m -cp $CP com.ankurm.nio2.ReadAllFail $m "$DATA/$f.log" 2>&1 | strip | tail -n +2; done; done echo; echo "How much heap does the 200 MB file need? (readAllLines, then readString)" for x in 256m 512m 1g 2g; do for m in readAllLines readString; do printf '%-13s -Xmx%-5s ' "$m" "$x"; "$J" -Xmx$x -cp $CP com.ankurm.nio2.ReadAllFail $m "$DATA/medium.log" 2>&1 | strip | tail -n 1; done; done; } > "$OUT/05-read-all-fail.txt" echo "==> handles" "$J" -cp $CP com.ankurm.nio2.HandleLeakDemo 2>&1 | strip > "$OUT/06-handle-leak.txt" { echo '$ ulimit -n 64; java HandleExhaustion'; (ulimit -n 64; "$J" -cp $CP com.ankurm.nio2.HandleExhaustion 2>&1 | strip); } > "$OUT/07-handle-exhaustion.txt" echo "==> walk / find" "$J" -cp $CP com.ankurm.nio2.WalkFindDemo 2>&1 | strip > "$OUT/08-walk-find.txt" "$J" -cp $CP com.ankurm.nio2.LinesCharsetDemo 2>&1 | strip > "$OUT/09-lines-charset.txt" echo "==> WatchService" "$J" -cp $CP com.ankurm.nio2.WatchDemo 2>&1 | strip > "$OUT/10-watch.txt" { echo '$ java -Djdk.nio.file.WatchService.maxEventsPerPoll=10000 WatchDemo (scenario 6 only)' "$J" -Djdk.nio.file.WatchService.maxEventsPerPoll=10000 -cp $CP com.ankurm.nio2.WatchDemo 2>&1 | strip | sed -n '/^6\./,$p' echo; echo "Scenario 3 (50 appends, no polling) over five more runs:" for i in 1 2 3 4 5; do "$J" -cp $CP com.ankurm.nio2.WatchDemo 2>&1 | strip | sed -n '/^3\./,/^4\./p' | sed '2!d'; done; } > "$OUT/11-watch-tuned-and-repeat.txt" unzip -p "$JDK25_HOME/lib/src.zip" java.base/sun/nio/fs/AbstractWatchKey.java | sed -n '/final void signalEvent/,/signal();/p' > "$OUT/12-watchkey-source-excerpt.txt" echo "==> memory-mapped" { echo '$ java -Xmx64m MappedDemo big.log'; "$J" -Xmx64m -cp $CP com.ankurm.nio2.MappedDemo "$DATA/big.log" 2>&1 | strip; } > "$OUT/13-mapped.txt" cp target/surefire-reports/com.ankurm.nio2.Nio2BehaviourTest.txt "$OUT/14-tests.txt" { echo '$ df -h (data directory, after deleting is done by the exit trap; shown here before)'; df -h "$DATA" | sed 's/ */ /g'; } >> "$OUT/01-environment.txt" echo Done