Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 6 | # Usage: GIT_REMOTE=https://git.coline.app/o/n.git VCS_PROJECT=upstream.codes/o/n \ |
| 7 | # VCS_TOKEN=... tests/bench-live.sh [path/to/vcs] [agents] |
| 8 | # git uses this machine's credentials for the remote. |
| 9 | set -uo pipefail |
| 10 |
| 11 | VCS=${1:-$(cd "$(dirname "$0")/.." && pwd)/target/release/vcs} |
| 12 | N=${2:-16} |
| 13 | WORK=$(mktemp -d) |
| 14 | export VCS_SAVER=0 VCS_HOME=$WORK/home VCS_NAME=Bench VCS_EMAIL=bench@example.com |
| 15 | export GIT_AUTHOR_NAME=Bench GIT_AUTHOR_EMAIL=bench@example.com GIT_COMMITTER_NAME=Bench GIT_COMMITTER_EMAIL=bench@example.com |
| 16 | BRANCH="bench-$(date +%s)" |
| 17 | trap 'rm -rf "$WORK"' EXIT |
| 18 | cd "$WORK" |
| 19 | g() { git -c commit.gpgsign=false "$@"; } |
| 20 | now() { python3 -c 'import time; print(time.time())'; } |
| 21 | since() { python3 -c "import time; print(f'{time.time() - $1:.2f}')"; } |
| 22 | med() { printf '%s\n' "$@" | sort -n | sed -n "$(( ($# + 1) / 2 ))p"; } |
| 23 | row() { printf '%-52s %10s %10s %10s\n' "$1" "$2" "$3" "$4"; } |
| 24 |
| 25 | "$VCS" login "${VCS_PROJECT%%/*}" --token "$VCS_TOKEN" >/dev/null |
| 26 | echo "live: git $GIT_REMOTE (branch $BRANCH) vs vcs $VCS_PROJECT" |
| 27 | echo "git land = the host merges the push onto the branch (git push origin HEAD:refs/land/<branch>)" |
| 28 | echo |
| 29 | row "" "git push" "git land" "vcs" |
| 30 |
| 31 | t=$(now); g clone -q "$GIT_REMOTE" g0; tg=$(since "$t") |
| 32 | t=$(now); "$VCS" get "$VCS_PROJECT" v0 >/dev/null; tv=$(since "$t") |
| 33 | row "first copy (s)" "$tg" "" "$tv" |
| 34 | (cd g0 && g checkout -q -b "$BRANCH" && g push -q origin "$BRANCH") |
| 35 |
| 36 | gl=() |
| 37 | ll=() |
| 38 | vl=() |
| 39 | for i in $(seq 1 5); do |
| 40 | printf '%s %s\n' "$BRANCH" "$i" >> g0/$BRANCH.txt |
| 41 | t=$(now); (cd g0 && g add -A && g commit -qm "Bench $i" && g push -q origin "$BRANCH"); gl+=("$(since "$t")") |
| 42 | printf '%s land %s\n' "$BRANCH" "$i" >> g0/$BRANCH.txt |
| 43 | t=$(now); (cd g0 && g add -A && g commit -qm "Bench land $i" && g push -q origin "HEAD:refs/land/$BRANCH"); ll+=("$(since "$t")") |
| 44 | printf '%s %s\n' "$BRANCH" "$i" >> v0/$BRANCH.txt |
| 45 | t=$(now); "$VCS" -C v0 land -m "Bench $i" >/dev/null; vl+=("$(since "$t")") |
| 46 | done |
| 47 | row "one change, median (s)" "$(med "${gl[@]}")" "$(med "${ll[@]}")" "$(med "${vl[@]}")" |
| 48 |
| 49 | for i in $(seq 1 "$N"); do |
| 50 | 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") |
| 51 | 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") |
| 52 | "$VCS" get "$VCS_PROJECT" "v$i" >/dev/null && printf '%s %s\n' "$BRANCH" "$i" > "v$i/$BRANCH-$i.txt" |
| 53 | done |
| 54 | pids=() |
| 55 | t=$(now) |
| 56 | for i in $(seq 1 "$N"); do |
| 57 | (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") & |
| 58 | pids+=($!) |
| 59 | done |
| 60 | wait "${pids[@]}" |
| 61 | tg=$(since "$t") |
| 62 | refused=$(cat tries* | python3 -c "import sys; print(sum(int(l) for l in sys.stdin))") |
| 63 | pids=() |
| 64 | t=$(now) |
| 65 | 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 |
| 66 | wait "${pids[@]}" |
| 67 | tl=$(since "$t") |
| 68 | glanded=$(grep -l '^0$' lcode* | wc -l | tr -d ' ') |
| 69 | pids=() |
| 70 | t=$(now) |
| 71 | for i in $(seq 1 "$N"); do ("$VCS" -C "v$i" land -m "Agent $i" >/dev/null 2>&1; echo $? > "vcode$i") & pids+=($!); done |
| 72 | wait "${pids[@]}" |
| 73 | tv=$(since "$t") |
| 74 | landed=$(grep -l '^0$' vcode* | wc -l | tr -d ' ') |
| 75 | row "$N agents land one change each on one branch (s)" "$tg" "$tl" "$tv" |
| 76 | row " refused pushes / changes that didn't land" "$refused" "$((N - glanded))" "$((N - landed))" |
| 77 | echo |
| 78 | echo "git scratch branch left on the remote: $BRANCH" |
| 79 |