#!/usr/bin/env bash # Onset 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, and through the host's landing, refs/land), Onset 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/on] [agents] # git uses this machine's credentials for the remote. set -uo pipefail VCS=${1:-$(cd "$(dirname "$0")/.." && pwd)/target/release/on} N=${2:-16} WORK=$(mktemp -d) export ONSET_SAVER=0 ONSET_HOME=$WORK/home ONSET_NAME=Bench ONSET_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 %10s %10s %10s\n' "$1" "$2" "$3" "$4"; } "$VCS" login "${VCS_PROJECT%%/*}" --token "$VCS_TOKEN" >/dev/null echo "live: git $GIT_REMOTE (branch $BRANCH) vs Onset $VCS_PROJECT" echo "git land = the host merges the push onto the branch (git push origin HEAD:refs/land/)" echo row "" "git push" "git land" "Onset" 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=() ll=() 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 land %s\n' "$BRANCH" "$i" >> g0/$BRANCH.txt t=$(now); (cd g0 && g add -A && g commit -qm "Bench land $i" && g push -q origin "HEAD:refs/land/$BRANCH"); ll+=("$(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, median (s)" "$(med "${gl[@]}")" "$(med "${ll[@]}")" "$(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") g clone -q --branch "$BRANCH" "$GIT_REMOTE" "l$i" && printf '%s land %s\n' "$BRANCH" "$i" > "l$i/$BRANCH-land-$i.txt" && (cd "l$i" && g add -A && g commit -qm "Agent land $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 (cd "l$i"; g push -q origin "HEAD:refs/land/$BRANCH" >/dev/null 2>&1; echo $? > "../lcode$i") & pids+=($!); done wait "${pids[@]}" tl=$(since "$t") glanded=$(grep -l '^0$' lcode* | wc -l | tr -d ' ') 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" "$tl" "$tv" row " refused pushes / changes that didn't land" "$refused" "$((N - glanded))" "$((N - landed))" echo echo "git scratch branch left on the remote: $BRANCH"