From e5e462b2f7a56087522104a2fc6427d42e63c839 Mon Sep 17 00:00:00 2001 From: tofarr Date: Mon, 30 Nov 2026 17:46:32 +0000 Subject: [PATCH] perf: add git clone + npm install benchmark (regular fs vs fusey mount) Co-authored-by: openhands --- .gitignore | 1 + perf/clone_npm_bench.sh | 209 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100755 perf/clone_npm_bench.sh diff --git a/.gitignore b/.gitignore index 126fe66..25f414d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ Thumbs.db # Quint .quint_cache/ +perf/results/ diff --git a/perf/clone_npm_bench.sh b/perf/clone_npm_bench.sh new file mode 100755 index 0000000..acdf1f5 --- /dev/null +++ b/perf/clone_npm_bench.sh @@ -0,0 +1,209 @@ +#!/usr/bin/env bash +# Performance benchmark: `git clone` + `npm install` on a regular filesystem +# vs. on a fusey FUSE mount. +# +# Usage: perf/clone_npm_bench.sh [regular|fuse|both] (default: both) +# +# Phases timed per target (wall-clock seconds): +# clone git clone $REPO_URL +# install npm install in $INSTALL_SUBDIR +# status git status (metadata-heavy: lstat of every file) +# walk find . | wc -l (readdir/stat of every entry) +# read tar cf - . | wc -c (sequential read of every file) +# rm_rf (fuse only) delete the clone +# unmount (fuse only) unmount + final index/chunk flush +# +# The fuse target uses the reference broker (broker/main.py) as its object +# store, so no S3 or Docker is needed. It needs /dev/fuse, fusermount3 (or +# root), python3 with fastapi+uvicorn, and a built fusey binary. +# +# Environment: +# REPO_URL repo to clone (default https://github.com/OpenHands/OpenHands) +# INSTALL_SUBDIR dir to run npm install in (default ".") +# CLONE_DEPTH if set, passes --depth (default: full clone) +# WORK_DIR scratch root (default: mktemp -d) +# RESULTS_DIR where results land (default: perf/results) +# FUSEY_BIN fusey binary (default: go build into WORK_DIR) +# BROKER_PYTHON python with fastapi (default: python3) +# BROKER_PORT broker listen port (default 18000) +# FUSEY_* passed through to fusey (e.g. FUSEY_CHUNK_SIZE) +set -uo pipefail + +MODE="${1:-both}" +REPO_URL="${REPO_URL:-https://github.com/OpenHands/OpenHands}" +INSTALL_SUBDIR="${INSTALL_SUBDIR:-.}" +CLONE_DEPTH="${CLONE_DEPTH:-}" +BROKER_PYTHON="${BROKER_PYTHON:-python3}" +BROKER_PORT="${BROKER_PORT:-18000}" + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +WORK_DIR="${WORK_DIR:-$(mktemp -d /tmp/fusey-perf.XXXXXX)}" +RESULTS_DIR="${RESULTS_DIR:-$ROOT/perf/results}" +mkdir -p "$WORK_DIR" "$RESULTS_DIR" +RESULTS_TSV="$RESULTS_DIR/clone_npm_$(date +%Y%m%dT%H%M%S).tsv" + +BROKER_PID="" +MOUNTED="" + +log() { echo "[perf] $*" >&2; } + +# record : append elapsed seconds (EPOCHREALTIME values). +record() { + awk -v t="$1" -v p="$2" -v a="$3" -v b="$4" 'BEGIN { printf "%s\t%s\t%.2f\n", t, p, b - a }' >>"$RESULTS_TSV" +} + +# timed : run cmd, record wall-clock seconds. +timed() { + local target="$1" phase="$2"; shift 2 + local t0 t1 rc + log "$target/$phase: $*" + t0=$EPOCHREALTIME + "$@" >"$WORK_DIR/$target.$phase.log" 2>&1 + rc=$? + t1=$EPOCHREALTIME + if [ $rc -ne 0 ]; then + log "$target/$phase FAILED (rc=$rc); see $WORK_DIR/$target.$phase.log" + tail -5 "$WORK_DIR/$target.$phase.log" >&2 + printf '%s\t%s\tFAIL\n' "$target" "$phase" >>"$RESULTS_TSV" + return $rc + fi + record "$target" "$phase" "$t0" "$t1" +} + +# run_workload : the benchmarked workload inside . +run_workload() { + local target="$1" dir="$2" clone_args=() + [ -n "$CLONE_DEPTH" ] && clone_args=(--depth "$CLONE_DEPTH") + local repo="$dir/repo" + + timed "$target" clone git clone --quiet "${clone_args[@]}" "$REPO_URL" "$repo" || return 1 + # Fresh per-target npm cache (on the regular fs) so every target downloads cold. + timed "$target" install bash -c \ + "cd '$repo/$INSTALL_SUBDIR' && npm_config_cache='$WORK_DIR/npm-cache-$target' npm install --no-audit --no-fund --loglevel=error" || return 1 + timed "$target" status git -C "$repo" status --porcelain + timed "$target" walk bash -c "find '$repo' | wc -l" + timed "$target" read bash -c "tar cf - -C '$repo' . | wc -c" + + { + printf '%s\tfiles\t%s\n' "$target" "$(find "$repo" | wc -l)" + printf '%s\tapparent_MiB\t%s\n' "$target" "$(du -sm --apparent-size "$repo" | cut -f1)" + } >>"$RESULTS_TSV" +} + +run_regular() { + local dir="$WORK_DIR/regular" + mkdir -p "$dir" + run_workload regular "$dir" + rm -rf "$dir" +} + +start_broker() { + local store="$WORK_DIR/broker_store" + mkdir -p "$store" + ( + cd "$ROOT/broker" && + FUSEY_STORE_DIR="$store" \ + FUSEY_BROKER_AUTH_VALUE=perf-token \ + FUSEY_BROKER_BASE_URL="http://127.0.0.1:$BROKER_PORT" \ + exec "$BROKER_PYTHON" -m uvicorn main:app --host 127.0.0.1 --port "$BROKER_PORT" --log-level warning + ) >"$WORK_DIR/broker.log" 2>&1 & + BROKER_PID=$! + for _ in $(seq 50); do + curl -s -o /dev/null "http://127.0.0.1:$BROKER_PORT/docs" && return 0 + sleep 0.2 + done + log "broker failed to start; see $WORK_DIR/broker.log" + return 1 +} + +run_fuse() { + FUSEY_BIN="${FUSEY_BIN:-$WORK_DIR/fusey}" + if [ ! -x "$FUSEY_BIN" ]; then + log "building fusey -> $FUSEY_BIN" + (cd "$ROOT" && go build -o "$FUSEY_BIN" ./cmd/fusey) || return 1 + fi + start_broker || return 1 + export FUSEY_BROKER_URL="http://127.0.0.1:$BROKER_PORT" + export FUSEY_BROKER_AUTH_VALUE=perf-token + export FUSEY_CACHE_DIR="$WORK_DIR/fusey-cache" + mkdir -p "$FUSEY_CACHE_DIR" + + local mnt="$WORK_DIR/mnt" + mkdir -p "$mnt" + if ! timed fuse mount "$FUSEY_BIN" mount "$mnt"; then + cat "$FUSEY_CACHE_DIR"/*/mount.log "$FUSEY_CACHE_DIR"/*/fusey.log 2>/dev/null >&2 + return 1 + fi + MOUNTED="$mnt" + + run_workload fuse "$mnt" + + local t0 t1 + t0=$EPOCHREALTIME + rm -rf "$mnt/repo" + t1=$EPOCHREALTIME + record fuse rm_rf "$t0" "$t1" + + t0=$EPOCHREALTIME + "$FUSEY_BIN" unmount "$mnt" >/dev/null + for _ in $(seq 600); do + ls "$FUSEY_CACHE_DIR"/*/daemon.pid >/dev/null 2>&1 || break + sleep 0.1 + done + t1=$EPOCHREALTIME + MOUNTED="" + record fuse unmount "$t0" "$t1" +} + +cleanup() { + if [ -n "$MOUNTED" ]; then + "${FUSEY_BIN:-fusey}" unmount "$MOUNTED" >/dev/null 2>&1 || true + sleep 1 + fi + [ -n "$BROKER_PID" ] && kill "$BROKER_PID" 2>/dev/null + return 0 +} +trap cleanup EXIT + +report() { + python3 - "$RESULTS_TSV" <<'EOF' +import collections +import sys + +rows = collections.defaultdict(dict) +for line in open(sys.argv[1]): + target, key, val = line.rstrip("\n").split("\t") + rows[target][key] = val + +phases = ["mount", "clone", "install", "status", "walk", "read", "rm_rf", "unmount"] +targets = [t for t in ("regular", "fuse") if t in rows] +both = len(targets) == 2 + +header = ["phase", *targets] + (["fuse / regular"] if both else []) +print("| " + " | ".join(header) + " |") +print("|" + "---|" * len(header)) +for p in phases: + vals = [rows[t].get(p) for t in targets] + if all(v is None for v in vals): + continue + cells = ["-" if v is None else v if v == "FAIL" else f"{float(v):.2f}s" for v in vals] + if both: + try: + cells.append(f"{float(vals[1]) / float(vals[0]):.2f}x") + except (TypeError, ValueError, ZeroDivisionError): + cells.append("-") + print(f"| {p} | " + " | ".join(cells) + " |") +for t in targets: + print(f"\n{t}: {rows[t].get('files', '?')} files, {rows[t].get('apparent_MiB', '?')} MiB apparent") +EOF +} + +log "results: $RESULTS_TSV (scratch: $WORK_DIR)" +case "$MODE" in + regular) run_regular ;; + fuse) run_fuse ;; + both) run_regular; run_fuse ;; + *) echo "usage: $0 [regular|fuse|both]" >&2; exit 2 ;; +esac +echo +report