Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 6 | set -uo pipefail |
| 7 |
| 8 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 9 | BIN=${1:-$ROOT/target/release} |
| 10 | VCS=$BIN/vcs |
| 11 | WORK=$(mktemp -d) |
| 12 | export VCS_SAVER=0 VCS_HOME=$WORK/home VCS_NAME=Perf VCS_EMAIL=perf@example.com |
| 13 | PORT=$((20000 + RANDOM % 20000)) |
| 14 | HOST="127.0.0.1:$PORT" |
| 15 | SERVER_PID= |
| 16 | cleanup() { |
| 17 | [ -n "$SERVER_PID" ] && kill "$SERVER_PID" 2>/dev/null |
| 18 | rm -rf "$WORK" |
| 19 | } |
| 20 | trap cleanup EXIT |
| 21 | cd "$WORK" |
| 22 |
| 23 | ms() { python3 -c "import time; print(int(time.time()*1000))"; } |
| 24 | best() { # runs a command 5 times, prints the fastest in ms |
| 25 | local b=999999 |
| 26 | for _ in 1 2 3 4 5; do |
| 27 | local t0; t0=$(ms); "$@" >/dev/null 2>&1; local t=$(($(ms) - t0)) |
| 28 | [ "$t" -lt "$b" ] && b=$t |
| 29 | done |
| 30 | echo "$b" |
| 31 | } |
| 32 | files() { # folder, count |
| 33 | python3 - "$1" "$2" <<'EOF' |
| 34 | import os, sys |
| 35 | root, n = sys.argv[1], int(sys.argv[2]) |
| 36 | for i in range(n): |
| 37 | d = os.path.join(root, "src", f"m{i // 20:04d}") |
| 38 | os.makedirs(d, exist_ok=True) |
| 39 | with open(os.path.join(d, f"f{i:05d}.ts"), "w") as f: |
| 40 | f.write(f"export const v{i} = {i};\n" * 30) |
| 41 | EOF |
| 42 | } |
| 43 |
| 44 | # Status on 20,000 files. |
| 45 | "$VCS" init big >/dev/null |
| 46 | files big 20000 |
| 47 | "$VCS" -C big land -m "20k files" >/dev/null |
| 48 | echo "status, 20,000 files, nothing changed: $(best "$VCS" -C big status) ms" |
| 49 | printf 'edit\n' >> big/src/m0500/f10000.ts |
| 50 | echo "status, 20,000 files, one changed: $(best "$VCS" -C big status) ms" |
| 51 |
| 52 | # A second workspace of a 15,000-file project, through a host. |
| 53 | "$BIN/vcs-server" user add perf --name Perf --email perf@example.com --data "$WORK/server" > token |
| 54 | VCS_SERVER_LOG=1 "$BIN/vcs-server" serve --data "$WORK/server" --listen "$HOST" --threads 16 2>"$WORK/server.log" & |
| 55 | SERVER_PID=$! |
| 56 | for _ in $(seq 50); do curl -s "http://$HOST/.well-known/vcs.json" >/dev/null && break; sleep 0.1; done |
| 57 | "$VCS" login "$HOST" --token "$(cat token)" >/dev/null |
| 58 | "$VCS" init mid >/dev/null |
| 59 | files mid 15000 |
| 60 | "$VCS" -C mid land -m "15k files" >/dev/null |
| 61 | t0=$(ms); "$VCS" -C mid publish "$HOST/perf/mid" >/dev/null; echo "publish 15,000 files: $(($(ms) - t0)) ms" |
| 62 | t0=$(ms); "$VCS" get "$HOST/perf/mid" ws1 >/dev/null; echo "first workspace, 15,000 files (objects already here): $(($(ms) - t0)) ms" |
| 63 | t0=$(ms); "$VCS" get "$HOST/perf/mid" ws2 >/dev/null; echo "second workspace, 15,000 files: $(($(ms) - t0)) ms" |
| 64 | t0=$(ms); VCS_HOME=$WORK/fresh "$VCS" login "$HOST" --token "$(cat token)" >/dev/null; VCS_HOME=$WORK/fresh "$VCS" get "$HOST/perf/mid" ws3 >/dev/null; echo "workspace on a new machine (downloads everything): $(($(ms) - t0)) ms" |
| 65 |
| 66 | # Landing: one at a time, then 64 at once. |
| 67 | for i in $(seq 1 64); do "$VCS" get "$HOST/perf/mid" "a$i" >/dev/null; printf 'agent %s\n' "$i" > "a$i/agent-$i.txt"; done |
| 68 | t0=$(ms); "$VCS" -C a1 land -m "One land" >/dev/null; echo "one land, whole command: $(($(ms) - t0)) ms" |
| 69 | t0=$(ms) |
| 70 | pids=() |
| 71 | for i in $(seq 2 64); do "$VCS" -C "a$i" land -m "Agent $i" >/dev/null 2>&1 & pids+=($!); done |
| 72 | wait "${pids[@]}" |
| 73 | total=$(($(ms) - t0)) |
| 74 | n=$(curl -s -H "authorization: Bearer $(cat token)" "http://$HOST/v1/projects/perf/mid" | python3 -c 'import json,sys; print(json.load(sys.stdin)["main"]["n"])') |
| 75 | echo "63 agents landing at once: $total ms for all, main at $n (expected 65)" |
| 76 | # The server's own time per land, from its request log ("POST .../land → 200 in 1.23ms"). |
| 77 | grep 'POST /v1/projects/perf/mid/land' "$WORK/server.log" | sed -E 's/.* in ([0-9.]+)(µs|ms|s)$/\1 \2/' | python3 -c ' |
| 78 | import sys |
| 79 | ms = sorted(float(v) * {"µs": 0.001, "ms": 1, "s": 1000}[u] for v, u in (l.split() for l in sys.stdin if l.strip())) |
| 80 | print(f"server time per land: median {ms[len(ms)//2]:.1f} ms, slowest {ms[-1]:.1f} ms, {len(ms)} lands; one main lands about {1000/ms[len(ms)//2]:.0f} per second") |
| 81 | ' |
| 82 |