feat: add pack optimization prompt, debug infrastructure, and monitoring scripts
Add a prompt template for optimizing the `pack` step and a suite of Docker-based debug tools including build, run, and monitoring scripts. Enhance `pack_matrices` with LFD partition sizing and detailed timing reports, and update `stop` with additional system statistics. - Add `prompts/pack_optimization.md` to guide optimization of the `pack` step, specifying context, performance measurements, and deliverable structures. - Add `scripts/docker_debug/` infrastructure: Dockerfile for musl targets, `build.sh` for image creation, `run.sh` for parallel indexing and merging, `monitor.sh` for PID tracking, `gen_fasta.py` for synthetic genomes, and `gen_fasta_real.py` for real genome generation with `read_fna`. - Add `scripts/monitor_pack.sh` as a 1 Hz sampler for I/O and memory metrics, writing samples to CSV and summary reports. - Add `scripts/watch_merge.sh` to monitor process resource usage, enforcing memory limits via SIGTERM/SIGKILL guards based on VmRSS and VmSize. - Modify `src/obikindex/src/index/kmer_index.rs`: add `pending_matrix_bytes` and `report_pack_timings`; update `pack_matrices` to use LFD strategy for partition sizing and clarify documentation regarding `stat()` proxy bytes. - Modify `src/obisys/src/stage.rs`: update `stop` definition to include new variables (`user_secs`, `sys_secs`, faults, context switches, I/O blocks) and logic checking for swap usage.
This commit is contained in:
1 parent
24291a4484
commit
03eaa4544a
11 files changed
+497
-2
No files matched your search
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env bash
|
||||
# run.sh — builds obikmer (release, debug symbols) and merges the benchmark presence
|
||||
# indexes in the container while sampling mappings/RSS/commit in parallel.
|
||||
#
|
||||
# Env:
|
||||
# PLATFORM linux/amd64 (default, Rosetta) | linux/arm64
|
||||
# GEN if set: build GEN synthetic indexes (gen_fasta.py) instead of using
|
||||
# the benchmark ones; GENOME_LEN (default 150000), K (21), M (9), PART (256)
|
||||
# REAL if set (with GEN): derive genomes from benchmark/run/genomes (gen_fasta_real.py)
|
||||
# SRC_DIR alternative source tree (default: <repo>/src); VARIANT: volume suffix;
|
||||
# LOCKED=0 to allow Cargo.lock changes (needed when a dep is added)
|
||||
# NSRC number of source indexes to merge (default: all 20)
|
||||
# TARGET gnu (default, glibc) | musl (static, same chain as the release CI)
|
||||
# TOOL none (default) | heaptrack (heaptrack output goes to OUT/)
|
||||
# MAXMAP if set, vm.max_map_count is lowered to this inside the VM for the
|
||||
# run and restored afterwards (needs --privileged; affects the whole
|
||||
# OrbStack VM while it runs)
|
||||
# MALLOC_ARENA_MAX, MALLOC_MMAP_THRESHOLD_, MALLOC_TRIM_THRESHOLD_ passed through
|
||||
# OUT host output directory (default: ./out/<timestamp>)
|
||||
set -euo pipefail
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO="$(cd "$HERE/../.." && pwd)"
|
||||
PLATFORM="${PLATFORM:-linux/amd64}"
|
||||
NSRC="${NSRC:-20}"
|
||||
TOOL="${TOOL:-none}"
|
||||
TARGET="${TARGET:-gnu}"
|
||||
OUT="${OUT:-$HERE/out/$(date +%Y%m%d-%H%M%S)}"
|
||||
mkdir -p "$OUT"
|
||||
IMG="obikmer-debug:${PLATFORM//\//-}"
|
||||
VOL="obikmer-debug-target-${PLATFORM//\//-}-${TARGET}${VARIANT:+-$VARIANT}"
|
||||
|
||||
docker run --rm --privileged --platform "$PLATFORM" \
|
||||
-v "${SRC_DIR:-$REPO/src}:/work/src:$([ -n "${SRC_DIR:-}" ] && echo rw || echo ro)" \
|
||||
-v "$REPO/benchmark/run/specimen_index_presence:/idx_ro:ro" \
|
||||
-v "$VOL:/target" \
|
||||
-v "$OUT:/out" \
|
||||
-v "$HERE/monitor.sh:/monitor.sh:ro" \
|
||||
-v "$HERE/gen_fasta.py:/gen_fasta.py:ro" \
|
||||
-v "$HERE/gen_fasta_real.py:/gen_fasta_real.py:ro" \
|
||||
-v "$REPO/benchmark/run/genomes:/genomes_ro:ro" \
|
||||
-e CARGO_TARGET_DIR=/target -e CARGO_PROFILE_RELEASE_DEBUG=1 \
|
||||
-e GEN="${GEN:-}" -e LOCKED_FLAG="$([ "${LOCKED:-1}" = 0 ] || echo --locked)" -e SEED="${SEED:-20261118}" -e REAL="${REAL:-}" -e GENOME_LEN="${GENOME_LEN:-150000}" -e K="${K:-21}" -e M="${M:-9}" -e PART="${PART:-256}" -e RUST_LOG="${RUST_LOG:-}" -e NSRC="$NSRC" -e TARGET="$TARGET" -e TOOL="$TOOL" -e MAXMAP="${MAXMAP:-}" \
|
||||
-e MALLOC_ARENA_MAX="${MALLOC_ARENA_MAX:-}" \
|
||||
-e CXXFLAGS="${CXXFLAGS:-}" \
|
||||
-e MALLOC_MMAP_THRESHOLD_="${MALLOC_MMAP_THRESHOLD_:-}" \
|
||||
-e MALLOC_TRIM_THRESHOLD_="${MALLOC_TRIM_THRESHOLD_:-}" \
|
||||
"$IMG" bash -c '
|
||||
set -euo pipefail
|
||||
for v in MALLOC_ARENA_MAX MALLOC_MMAP_THRESHOLD_ MALLOC_TRIM_THRESHOLD_ RUST_LOG; do
|
||||
[ -n "${!v}" ] || unset $v
|
||||
done
|
||||
if [ "$TARGET" = musl ]; then
|
||||
PKG_CONFIG_ALLOW_CROSS=1 cargo zigbuild --release $LOCKED_FLAG --target x86_64-unknown-linux-musl \
|
||||
--manifest-path /work/src/Cargo.toml --bin obikmer 2>&1 | tail -3
|
||||
BIN=/target/x86_64-unknown-linux-musl/release/obikmer
|
||||
else
|
||||
cargo build --release $LOCKED_FLAG --manifest-path /work/src/Cargo.toml --bin obikmer 2>&1 | tail -3
|
||||
BIN=/target/release/obikmer
|
||||
fi
|
||||
file "$BIN" 2>/dev/null | cut -c1-150 || true
|
||||
# merge writes into its sources (lock files…): work on a copy, never on benchmark/
|
||||
rm -rf /tmp/idx && mkdir -p /tmp/idx
|
||||
if [ -n "$GEN" ]; then
|
||||
mkdir -p /tmp/fa
|
||||
if [ -n "$REAL" ]; then python3 /gen_fasta_real.py "$GEN" /tmp/fa /genomes_ro "$GENOME_LEN" "$SEED"
|
||||
else python3 /gen_fasta.py "$GEN" /tmp/fa "$GENOME_LEN" "$SEED"; fi
|
||||
NSRC=$GEN
|
||||
echo "indexing $GEN synthetic genomes (k=$K m=$M p=$PART)…"
|
||||
ls /tmp/fa/*.fasta | xargs -P 8 -I{} sh -c \
|
||||
"b=\$(basename {} .fasta); $BIN index -k $K -m $M --theta 0 -p $PART --label \$b -o /tmp/idx/\$b.idx {} >/dev/null 2>&1 || echo index failed: \$b"
|
||||
else
|
||||
cp -r /idx_ro/. /tmp/idx/
|
||||
fi
|
||||
mapfile -t SRC < <(find /tmp/idx -mindepth 1 -maxdepth 1 -type d | sort | head -n "$NSRC")
|
||||
echo "sources: ${#SRC[@]} target: $TARGET tool: $TOOL max_map_count: $(cat /proc/sys/vm/max_map_count)"
|
||||
if [ -n "$MAXMAP" ]; then
|
||||
OLD=$(cat /proc/sys/vm/max_map_count); sysctl -w vm.max_map_count="$MAXMAP" >/dev/null
|
||||
trap "sysctl -w vm.max_map_count=$OLD >/dev/null" EXIT
|
||||
fi
|
||||
rm -rf /tmp/merged
|
||||
CMD=("$BIN" merge --output /tmp/merged --force --force-presence "${SRC[@]}")
|
||||
if [ "$TOOL" = heaptrack ]; then CMD=(heaptrack -o /out/heaptrack "${CMD[@]}"); fi
|
||||
"${CMD[@]}" 2>/out/merge.stderr &
|
||||
PID=$!
|
||||
/monitor.sh "$PID" /out/monitor.csv 1 &
|
||||
MON=$!
|
||||
set +e; wait "$PID"; RC=$?; set -e
|
||||
wait "$MON" || true
|
||||
echo "merge exit code: $RC" | tee /out/exit_code.txt
|
||||
tail -5 /out/merge.stderr
|
||||
'
|
||||
echo "outputs: $OUT"
|
||||
Reference in new issue
Block a user