#!/usr/bin/env bash # vcs against stock git on live hosts, from one machine: git through a git # remote (pushing to a scratch branch, with pull --rebase and push again # when refused), vcs through a hosted project. # Usage: GIT_REMOTE=https://git.coline.app/o/n.git VCS_PROJECT=upstream.codes/o/n \ # VCS_TOKEN=... tests/bench-live.sh [path/to/vcs] [agents] # git uses this machine's credentials for the remote. set -uo pipefail VCS=${1:-$(cd "$(dirname "$0")/.." && pwd)/target/release/vcs} N=${2:-16} WORK=$(mktemp -d) export VCS_SAVER=0 VCS_HOME=$WORK/home VCS_NAME=Bench VCS_EMAIL=bench@example.com export GIT_AUTHOR_NAME=Bench GIT_AUTHOR_EMAIL=bench@example.com GIT_COMMITTER_NAME=Bench GIT_COMMITTER_EMAIL=bench@example.com BRANCH="bench-$(date +%s)" trap 'rm -rf "$WORK"' EXIT cd "$WORK" g() { git -c commit.gpgsign=false "$@"; } now() { python3 -c 'import time; print(time.time())'; } since() { python3 -c "import time; print(f'{time.time() - $1:.2f}')"; } med() { printf '%s\n' "$@" | sort -n | sed -n "$(( ($# + 1) / 2 ))p"; } row() { printf '%-52s %12s %12s\n' "$1" "$2" "$3"; } "$VCS" login "${VCS_PROJECT%%/*}" --token "$VCS_TOKEN" >/dev/null echo "live: git $GIT_REMOTE (branch $BRANCH) vs vcs $VCS_PROJECT" echo row "" "git" "vcs" t=$(now); g clone -q "$GIT_REMOTE" g0; tg=$(since "$t") t=$(now); "$VCS" get "$VCS_PROJECT" v0 >/dev/null; tv=$(since "$t") row "first copy (s)" "$tg" "$tv" (cd g0 && g checkout -q -b "$BRANCH" && g push -q origin "$BRANCH") gl=() vl=() for i in $(seq 1 5); do printf '%s %s\n' "$BRANCH" "$i" >> g0/$BRANCH.txt t=$(now); (cd g0 && g add -A && g commit -qm "Bench $i" && g push -q origin "$BRANCH"); gl+=("$(since "$t")") printf '%s %s\n' "$BRANCH" "$i" >> v0/$BRANCH.txt t=$(now); "$VCS" -C v0 land -m "Bench $i" >/dev/null; vl+=("$(since "$t")") done row "one change: commit + push vs land, median (s)" "$(med "${gl[@]}")" "$(med "${vl[@]}")" for i in $(seq 1 "$N"); do g clone -q --branch "$BRANCH" "$GIT_REMOTE" "g$i" && printf '%s %s\n' "$BRANCH" "$i" > "g$i/$BRANCH-$i.txt" && (cd "g$i" && g add -A && g commit -qm "Agent $i") "$VCS" get "$VCS_PROJECT" "v$i" >/dev/null && printf '%s %s\n' "$BRANCH" "$i" > "v$i/$BRANCH-$i.txt" done pids=() t=$(now) for i in $(seq 1 "$N"); do (cd "g$i"; tries=0; until g push -q origin "$BRANCH" 2>/dev/null; do tries=$((tries + 1)); [ "$tries" -gt 200 ] && break; g pull -q --rebase origin "$BRANCH" 2>/dev/null; done; echo "$tries" > "../tries$i") & pids+=($!) done wait "${pids[@]}" tg=$(since "$t") refused=$(cat tries* | python3 -c "import sys; print(sum(int(l) for l in sys.stdin))") pids=() t=$(now) for i in $(seq 1 "$N"); do ("$VCS" -C "v$i" land -m "Agent $i" >/dev/null 2>&1; echo $? > "vcode$i") & pids+=($!); done wait "${pids[@]}" tv=$(since "$t") landed=$(grep -l '^0$' vcode* | wc -l | tr -d ' ') row "$N agents land one change each on one branch (s)" "$tg" "$tv" row " refused pushes / changes that didn't land" "$refused" "$((N - landed))" echo echo "git scratch branch left on the remote: $BRANCH"