Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 30 minutes ago History
dbbench · 20.5 KB · 366 lines
1#!/usr/bin/env bash
2# dbbench -- repeatable benchmarks for dbbasic-object-server.
3#
4# dbbench check is this machine in a fair state to measure?
5# dbbench storage [opts] in-process storage micro-benchmarks
6# dbbench http [opts] HTTP load test against a freshly started server
7# dbbench all [opts] both, under one label
8# dbbench compare A B [--threshold 5] diff two labelled runs (labels or .json paths)
9# dbbench list saved results, newest first
10#
11# Common options: --label NAME name this run (default: "run"); compare uses it
12# --python PATH interpreter (default $DBB_PYTHON or the repo's .venv-jit)
13# storage options: --sizes 1000,10000,100000 --repeat 5
14# http options: --server uvicorn|granian|granian-rsgi --workers 1
15# --loop auto|asyncio|uvloop|rloop (granian) --rows 10000
16# --conns 32 --duration 10 --repeat 3 --writes 500
17#
18# Runtime switches are plain environment variables, so one script covers every
19# variant: PYTHON_JIT=0|1 PYTHON_GIL=0|1 (free-threaded build only)
20#
21# Needs: bash, curl, jq, oha, python (+ uvicorn / granian for http). Writes only
22# to a temp dir and to $DBB_RESULTS_DIR (default scripts/bench/results). It never
23# touches real application data: every server runs on a freshly seeded temp dir.
24set -euo pipefail
25
26HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27REPO="$(cd "$HERE/../.." && pwd)"
28RESULTS="${DBB_RESULTS_DIR:-$HERE/results}"
29PY="${DBB_PYTHON:-$REPO/.venv-jit/bin/python}"
30TOKEN="benchtoken"
31export PATH="/opt/homebrew/bin:$PATH"
32
33die() { echo "dbbench: $*" >&2; exit 1; }
34note() { echo "$*" >&2; }
35need() { command -v "$1" >/dev/null 2>&1 || die "missing required tool: $1 ($2)"; }
36
37# ---------------------------------------------------------------- environment
38host_json() {
39 local cpu mem ncpu batt lpm
40 cpu="$(sysctl -n machdep.cpu.brand_string 2>/dev/null || uname -m)"
41 mem="$(( $(sysctl -n hw.memsize 2>/dev/null || echo 0) / 1073741824 ))"
42 ncpu="$(sysctl -n hw.ncpu 2>/dev/null || echo 0)"
43 batt="$(pmset -g batt 2>/dev/null | head -1 | sed -e "s/Now drawing from '\(.*\)'/\1/" || true)"
44 lpm="$(pmset -g 2>/dev/null | awk '/lowpowermode/ {print $2}' || true)"
45 jq -n --arg cpu "$cpu" --argjson mem "$mem" --argjson ncpu "$ncpu" --arg power "${batt:-unknown}" \
46 --arg lpm "${lpm:-unknown}" --arg os "$(uname -sr)" \
47 '{cpu:$cpu, mem_gb:$mem, cores:$ncpu, power:$power, low_power_mode:$lpm, os:$os}'
48}
49
50git_json() {
51 local commit dirty
52 commit="$(git -C "$REPO" rev-parse --short HEAD 2>/dev/null || echo unknown)"
53 dirty="$(git -C "$REPO" status --porcelain -- . ':!scripts/bench' 2>/dev/null | wc -l | tr -d ' ')"
54 jq -n --arg c "$commit" --argjson d "${dirty:-0}" '{commit:$c, dirty_files:$d}'
55}
56
57runtime_json() {
58 "$PY" - <<'PY'
59import json, platform, sys, os
60gil = getattr(sys, "_is_gil_enabled", None)
61jit = getattr(sys, "_jit", None)
62try: jit_on = bool(jit.is_enabled()) if jit else False
63except Exception: jit_on = None
64print(json.dumps({"python": sys.version.split()[0], "executable": sys.executable,
65 "gil_enabled": bool(gil()) if gil else True, "jit_enabled": jit_on,
66 "PYTHON_JIT": os.environ.get("PYTHON_JIT"), "PYTHON_GIL": os.environ.get("PYTHON_GIL")}))
67PY
68}
69
70# Prints warnings (one per line) about things that make timings unfair.
71preflight_warnings() {
72 local load ncpu busy
73 load="$(sysctl -n vm.loadavg 2>/dev/null | awk '{print $2}')"
74 ncpu="$(sysctl -n hw.ncpu 2>/dev/null || echo 1)"
75 if [ -n "${load:-}" ] && awk -v l="$load" -v n="$ncpu" 'BEGIN{exit !(l > n*0.35)}'; then
76 echo "1-minute load average is $load on $ncpu cores: the machine is not idle"
77 fi
78 pmset -g batt 2>/dev/null | head -1 | grep -qi "battery power" && echo "running on battery power (CPU may be throttled)"
79 pmset -g 2>/dev/null | awk '/lowpowermode/ {exit !($2 == 1)}' && echo "Low Power Mode is on"
80 busy="$(ps -Ao pcpu,comm 2>/dev/null | awk '$1 > 25 {print $2 " (" $1 "% cpu)"}' | head -3 | tr '\n' ' ' || true)"
81 [ -n "${busy:-}" ] && echo "busy processes: $busy"
82 pgrep -x ollama >/dev/null 2>&1 && echo "ollama is running (holds memory, may compete for the GPU/CPU)"
83 return 0
84}
85
86cmd_check() {
87 need jq "brew install jq"; need curl "built in"
88 echo "repo: $REPO ($(git_json | jq -r '"\(.commit), \(.dirty_files) modified files"'))"
89 echo "python: $(runtime_json | jq -c .)"
90 echo "host: $(host_json | jq -c .)"
91 for t in oha hyperfine; do
92 printf "%-9s %s\n" "$t:" "$(command -v "$t" || echo 'MISSING (brew install '"$t"')')"
93 done
94 for m in uvicorn granian; do
95 printf "%-9s %s\n" "$m:" "$("$PY" -c "import importlib.metadata as m;print(m.version('$m'))" 2>/dev/null || echo 'MISSING')"
96 done
97 local w; w="$(preflight_warnings)"
98 if [ -n "$w" ]; then echo; echo "WARNINGS (timings will be noisier):"; echo "$w" | sed 's/^/ - /'; else echo; echo "machine looks idle: OK to measure"; fi
99}
100
101# ------------------------------------------------------------------- storage
102save_result() { # save_result KIND LABEL FILE_WITH_BODY_JSON -> prints path
103 local kind="$1" label="$2" body="$3" out stamp warns
104 mkdir -p "$RESULTS"
105 stamp="$(date -u +%Y%m%dT%H%M%SZ)"
106 out="$RESULTS/${stamp}_${label}_${kind}.json"
107 warns="$(preflight_warnings | jq -R . | jq -s .)"
108 jq -n --arg label "$label" --arg kind "$kind" --arg at "$(date -u +%FT%TZ)" \
109 --argjson git "$(git_json)" --argjson host "$(host_json)" --argjson runtime "$(runtime_json)" \
110 --argjson warnings "$warns" --slurpfile body "$body" \
111 '{label:$label, kind:$kind, created:$at, git:$git, host:$host, runtime:$runtime, warnings:$warnings} + $body[0]' > "$out"
112 echo "$out"
113}
114
115cmd_storage() {
116 local sizes="1000,10000,100000" repeat=5 label="run"
117 while [ $# -gt 0 ]; do case "$1" in
118 --sizes) sizes="$2"; shift 2;; --repeat) repeat="$2"; shift 2;;
119 --label) label="$2"; shift 2;; --python) PY="$2"; shift 2;;
120 *) die "storage: unknown option $1";; esac; done
121 need jq "brew install jq"
122 TMP="$(mktemp -d)"; trap 'rm -rf "${TMP:-}"' EXIT
123 local tmp="$TMP"
124 local w; w="$(preflight_warnings)"; [ -n "$w" ] && { note "WARNING: machine is not quiet:"; echo "$w" | sed 's/^/ - /' >&2; }
125 note "storage benchmark: sizes=$sizes repeat=$repeat label=$label"
126 "$PY" "$HERE/storage_bench.py" --sizes "$sizes" --repeat "$repeat" --workdir "$tmp/work" > "$tmp/body.json"
127 local out; out="$(save_result storage "$label" "$tmp/body.json")"
128 note "saved: $out"
129 jq -r '.cases | to_entries[] | .key as $c | .value.ops | to_entries[]
130 | [$c, .key, (.value.median_ms|tostring), (.value.p95_ms|tostring)] | @tsv' "$out" \
131 | (printf 'case\toperation\tmedian_ms\tp95_ms\n'; cat) | column -t -s "$(printf '\t')"
132 rm -rf "$TMP"; trap - EXIT
133}
134
135# ---------------------------------------------------------------------- http
136SERVER_PID=""
137TMP=""
138stop_server() {
139 [ -n "$SERVER_PID" ] || return 0
140 pkill -TERM -P "$SERVER_PID" 2>/dev/null || true
141 kill -TERM "$SERVER_PID" 2>/dev/null || true
142 local i; for i in 1 2 3 4 5 6 7 8 9 10; do kill -0 "$SERVER_PID" 2>/dev/null || break; sleep 0.3; done
143 pkill -KILL -P "$SERVER_PID" 2>/dev/null || true
144 kill -KILL "$SERVER_PID" 2>/dev/null || true
145 wait "$SERVER_PID" 2>/dev/null || true
146 SERVER_PID=""
147}
148
149server_rss_mb() { # resident memory of the server and its children, MB
150 [ -n "$SERVER_PID" ] || { echo 0; return; }
151 { echo "$SERVER_PID"; pgrep -P "$SERVER_PID" 2>/dev/null || true; } \
152 | xargs -I{} ps -o rss= -p {} 2>/dev/null | awk '{s+=$1} END {printf "%.0f", s/1024}'
153}
154
155oha_summary() { # compact JSON from one oha result file
156 jq -c '{rps: ((.summary.requestsPerSec*10|round)/10),
157 p50_ms: ((.latencyPercentiles.p50*1000*100|round)/100),
158 p95_ms: ((.latencyPercentiles.p95*1000*100|round)/100),
159 p99_ms: ((.latencyPercentiles.p99*1000*100|round)/100),
160 max_ms: ((.summary.slowest*1000*10|round)/10),
161 ok: ([.statusCodeDistribution|to_entries[]|select(.key|startswith("2"))|.value]|add // 0),
162 non2xx: ([.statusCodeDistribution|to_entries[]|select(.key|startswith("2")|not)|.value]|add // 0),
163 status: .statusCodeDistribution,
164 errors: ([.errorDistribution|to_entries[]|select(.key!="aborted due to deadline")|.value]|add // 0)}' "$1"
165}
166
167cmd_http() {
168 local server="uvicorn" workers=1 loop="auto" rows=10000 conns=32 duration=10 repeat=3 writes=500 label="run"
169 while [ $# -gt 0 ]; do case "$1" in
170 --server) server="$2"; shift 2;; --workers) workers="$2"; shift 2;; --loop) loop="$2"; shift 2;;
171 --rows) rows="$2"; shift 2;; --conns) conns="$2"; shift 2;; --duration) duration="$2"; shift 2;;
172 --repeat) repeat="$2"; shift 2;; --writes) writes="$2"; shift 2;;
173 --label) label="$2"; shift 2;; --python) PY="$2"; shift 2;;
174 *) die "http: unknown option $1";; esac; done
175 need jq "brew install jq"; need curl "built in"; need oha "brew install oha"
176 [ "$conns" -le 64 ] || note "WARNING: --conns above 64 will hit the server's own DBBASIC_MAX_CONCURRENT_REQUESTS=64 cap (503s)"
177
178 local port base; TMP="$(mktemp -d)"; local tmp="$TMP"
179 port="$("$PY" -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1]);s.close()')"
180 base="http://127.0.0.1:$port"
181 trap 'stop_server; rm -rf "${TMP:-}"' EXIT INT TERM
182
183 local w; w="$(preflight_warnings)"; [ -n "$w" ] && { note "WARNING: machine is not quiet:"; echo "$w" | sed 's/^/ - /' >&2; }
184 note "http benchmark: server=$server workers=$workers rows=$rows conns=$conns duration=${duration}s repeat=$repeat writes=$writes label=$label"
185
186 "$PY" "$HERE/seed_tsv.py" "$tmp/data" "$tmp/urls" "$base" "$rows"
187 mkdir -p "$tmp/objects"
188
189 local -a cmd
190 case "$server" in
191 uvicorn) cmd=("$PY" -m uvicorn object_server:app --host 127.0.0.1 --port "$port" --workers "$workers" --log-level warning --no-access-log);;
192 granian) cmd=("$PY" -m granian --interface asgi --host 127.0.0.1 --port "$port" --workers "$workers" --loop "$loop" --log-level warning object_server:app);;
193 granian-rsgi) cmd=("$PY" -m granian --interface rsgi --host 127.0.0.1 --port "$port" --workers "$workers" --loop "$loop" --log-level warning "${DBB_RSGI_TARGET:-object_server_rsgi:app}");;
194 *) die "unknown --server $server (uvicorn | granian | granian-rsgi)";;
195 esac
196
197 ( cd "$REPO" && exec env -u DBBASIC_RATE_LIMIT_REQUESTS \
198 DBBASIC_OBJECTS_DIR="$tmp/objects" DBBASIC_DATA_DIR="$tmp/data" \
199 DBBASIC_ADMIN_TOKEN="$TOKEN" DBBASIC_COOKIE_SECURE=false \
200 "${cmd[@]}" ) > "$tmp/server.log" 2>&1 &
201 SERVER_PID=$!
202
203 local i ready=""
204 for i in $(seq 1 80); do
205 kill -0 "$SERVER_PID" 2>/dev/null || { tail -20 "$tmp/server.log" >&2; die "server exited during startup"; }
206 curl -fsS -m 2 "$base/health" >/dev/null 2>&1 && { ready=1; break; }
207 sleep 0.5
208 done
209 [ -n "$ready" ] || { tail -20 "$tmp/server.log" >&2; die "server did not become ready in 40s"; }
210
211 local total
212 total="$(curl -fsS -m 30 -H "Authorization: Token $TOKEN" "$base/collections/bench/records?limit=1" | jq -r '.total')" \
213 || die "could not read the seeded collection"
214 [ "$total" = "$rows" ] || die "seeded $rows rows but the server reports $total -- refusing to benchmark the wrong data"
215 local rss_start; rss_start="$(server_rss_mb)"
216
217 local -a auth=(-H "Authorization: Token $TOKEN" -H "Accept: application/json")
218 local body_create='{"title":"created by bench","qty":"1","status":"open","owner":"bench","note":"load test"}'
219 local body_update='{"status":"done","note":"updated by bench"}'
220 local wl_json="{}" name
221
222 run_workload() { # run_workload NAME KIND(time|count) oha-args...
223 local name="$1" kind="$2"; shift 2
224 local -a runs=() lim
225 if [ "$kind" = time ]; then lim=(-z "${duration}s"); else lim=(-n "$writes"); fi
226 if [ "$kind" = time ]; then # warm-up, discarded
227 oha -z 2s -c "$conns" --no-tui --output-format json "$@" > "$tmp/warm.json" 2>/dev/null || true
228 fi
229 local r
230 for r in $(seq 1 "$repeat"); do
231 note " $name run $r/$repeat"
232 oha "${lim[@]}" -c "$conns" --no-tui --output-format json "$@" > "$tmp/$name.$r.json" 2> "$tmp/oha.err" \
233 || { cat "$tmp/oha.err" >&2; die "oha failed on $name"; }
234 runs+=("$(oha_summary "$tmp/$name.$r.json")")
235 done
236 local arr; arr="$(printf '%s\n' "${runs[@]}" | jq -s '.')"
237 local bad; bad="$(echo "$arr" | jq '[.[].non2xx, .[].errors] | add')"
238 [ "$bad" = "0" ] || note " !! $name: $bad requests were not 2xx or failed (see 'status' in the saved result) -- numbers are suspect"
239 wl_json="$(echo "$wl_json" | jq --arg n "$name" --argjson a "$arr" \
240 '. + {($n): {runs:$a, rps_median:($a|map(.rps)|sort|.[(length/2|floor)]), rps_min:($a|map(.rps)|min), rps_max:($a|map(.rps)|max),
241 p99_ms_median:($a|map(.p99_ms)|sort|.[(length/2|floor)])}}')"
242 }
243
244 run_workload health time "${auth[@]}" "$base/health"
245 run_workload get_one time "${auth[@]}" --urls-from-file "$tmp/urls/get_one.txt"
246 run_workload list_page time "${auth[@]}" --urls-from-file "$tmp/urls/list_page.txt"
247 run_workload create_append count "${auth[@]}" -m POST -T application/json -d "$body_create" "$base/collections/bench_log/records"
248 run_workload create_classic count "${auth[@]}" -m POST -T application/json -d "$body_create" "$base/collections/bench_small/records"
249 run_workload update_one count "${auth[@]}" -m PUT -T application/json -d "$body_update" --urls-from-file "$tmp/urls/update_one.txt"
250
251 local rss_end; rss_end="$(server_rss_mb)"
252 jq -n --arg server "$server" --argjson workers "$workers" --arg loop "$loop" --argjson rows "$rows" \
253 --argjson conns "$conns" --argjson duration "$duration" --argjson repeat "$repeat" --argjson writes "$writes" \
254 --argjson rss0 "${rss_start:-0}" --argjson rss1 "${rss_end:-0}" --argjson wl "$wl_json" \
255 --arg oha "$(oha --version | awk '{print $2}')" \
256 '{http:{server:$server, workers:$workers, loop:$loop, rows:$rows, conns:$conns, duration_s:$duration,
257 repeat:$repeat, writes_per_run:$writes, oha:$oha, server_rss_mb:{start:$rss0, end:$rss1}, workloads:$wl}}' > "$tmp/body.json"
258 stop_server
259 local out; out="$(save_result http "$label" "$tmp/body.json")"
260 note "saved: $out"
261 jq -r '.http.workloads | to_entries[]
262 | [.key, (.value.rps_median|tostring), "\(.value.rps_min)-\(.value.rps_max)", (.value.p99_ms_median|tostring)] | @tsv' "$out" \
263 | (printf 'workload\treq_per_s\trange\tp99_ms\n'; cat) | column -t -s "$(printf '\t')"
264 jq -r '.http | "server rss: \(.server_rss_mb.start) MB -> \(.server_rss_mb.end) MB"' "$out"
265 trap - EXIT INT TERM; rm -rf "$TMP"
266}
267
268# ------------------------------------------------------------------- compare
269resolve() { # resolve LABEL_OR_FILE KIND -> path or empty
270 local a="$1" kind="$2"
271 if [ -f "$a" ]; then
272 [ "$(jq -r .kind "$a")" = "$kind" ] && echo "$a"
273 return 0
274 fi
275 ls -1 "$RESULTS"/*_"${a}"_"${kind}".json 2>/dev/null | sort | tail -1 || true
276}
277
278cmd_compare() {
279 local a="" b="" threshold=5
280 while [ $# -gt 0 ]; do case "$1" in
281 --threshold) threshold="$2"; shift 2;;
282 *) if [ -z "$a" ]; then a="$1"; elif [ -z "$b" ]; then b="$1"; else die "compare: too many arguments"; fi; shift;; esac; done
283 [ -n "$a" ] && [ -n "$b" ] || die "usage: dbbench compare BEFORE AFTER [--threshold PCT]"
284 need jq "brew install jq"
285 local kind fa fb found=0
286 for kind in storage http; do
287 fa="$(resolve "$a" "$kind")"; fb="$(resolve "$b" "$kind")"
288 [ -n "$fa" ] && [ -n "$fb" ] || continue
289 found=1
290 echo
291 echo "== $kind: $(jq -r .label "$fa") ($(jq -r '.git.commit' "$fa")) -> $(jq -r .label "$fb") ($(jq -r '.git.commit' "$fb"))"
292 jq -nr --slurpfile a "$fa" --slurpfile b "$fb" '
293 def rt: "python \(.runtime.python) gil=\(.runtime.gil_enabled) jit=\(.runtime.jit_enabled)";
294 " before: \($a[0]|rt)" + (if $a[0].http then " | \($a[0].http|"\(.server) w=\(.workers) loop=\(.loop) rows=\(.rows)")" else "" end),
295 " after: \($b[0]|rt)" + (if $b[0].http then " | \($b[0].http|"\(.server) w=\(.workers) loop=\(.loop) rows=\(.rows)")" else "" end),
296 (if ($a[0].git.dirty_files > 0 or $b[0].git.dirty_files > 0) then " note: a run had uncommitted changes in the repo (before \($a[0].git.dirty_files), after \($b[0].git.dirty_files) files)" else empty end),
297 (if ($a[0].warnings|length) > 0 or ($b[0].warnings|length) > 0 then " note: a run was measured on a busy machine; treat small differences as noise" else empty end)'
298 if [ "$kind" = storage ]; then
299 jq -nr --slurpfile a "$fa" --slurpfile b "$fb" --argjson t "$threshold" '
300 [ $a[0].cases | to_entries[] | .key as $c | .value.ops | to_entries[] | {k:"\($c)|\(.key)", v:.value.median_ms} ] as $A
301 | [ $b[0].cases | to_entries[] | .key as $c | .value.ops | to_entries[] | {k:"\($c)|\(.key)", v:.value.median_ms} ] as $B
302 | ($B | map({(.k): .v}) | add) as $bm
303 | $A[] | select($bm[.k] != null)
304 | (($bm[.k] - .v) / (if .v == 0 then 1e-9 else .v end) * 100) as $d
305 | ((.k|split("|")) + [(.v|tostring), ($bm[.k]|tostring), (($d*10|round)/10|tostring) + "%",
306 (if ($d|fabs) < $t or (($bm[.k] - .v)|fabs) < 0.02 then "~ same" elif $d < 0 then "FASTER" else "SLOWER" end)]) | @tsv' \
307 | (printf 'case\toperation\tbefore_ms\tafter_ms\tchange\tverdict\n'; cat) | column -t -s "$(printf '\t')"
308 else
309 jq -nr --slurpfile a "$fa" --slurpfile b "$fb" --argjson t "$threshold" '
310 $a[0].http.workloads as $A | $b[0].http.workloads as $B
311 | $A | to_entries[] | select($B[.key] != null) | .key as $k | .value as $x | $B[$k] as $y
312 | (($x.runs|length) >= 2 and ($y.runs|length) >= 2) as $have
313 | ($k | test("^(create|update)_") and ($x.runs|length) == ($y.runs|length) and $have) as $paired
314 # Write workloads change the data they run against (events fill toward their cap,
315 # files grow), so run N is not a repeat of run 1: compare run N with run N, not the
316 # spread between runs, which is built in and would hide a real change as "noise".
317 | ([range(0; ([($x.runs|length), ($y.runs|length)] | min))]
318 | map(($y.runs[.].rps - $x.runs[.].rps) / $x.runs[.].rps * 100)) as $pd
319 | (if $paired then ($pd | sort | .[(length/2|floor)])
320 else (($y.rps_median - $x.rps_median) / $x.rps_median * 100) end) as $d
321 | ([ (($x.rps_max - $x.rps_min) / $x.rps_median * 100), (($y.rps_max - $y.rps_min) / $y.rps_median * 100) ] | max) as $noise
322 | [$k, ($x.rps_median|tostring), ($y.rps_median|tostring), (($d*10|round)/10|tostring) + "%",
323 ($x.p99_ms_median|tostring), ($y.p99_ms_median|tostring),
324 (if $paired then
325 (if ($pd|all(. > $t)) then "FASTER (every paired run)"
326 elif ($pd|all(. < -$t)) then "SLOWER (every paired run)"
327 else "~ same (paired runs disagree)" end)
328 elif ($d|fabs) <= ([$t, (if $have then $noise else 0 end)]|max) then (if $have then "~ same (run-to-run spread \(($noise*10|round)/10)%)" else "~ same (only 1 run: spread unknown)" end)
329 elif $d > 0 then "FASTER" + (if $have then "" else " (1 run: unconfirmed)" end)
330 else "SLOWER" + (if $have then "" else " (1 run: unconfirmed)" end) end)] | @tsv' \
331 | (printf 'workload\tbefore_rps\tafter_rps\tchange\tp99_before_ms\tp99_after_ms\tverdict\n'; cat) | column -t -s "$(printf '\t')"
332 fi
333 done
334 [ "$found" = 1 ] || die "no matching results to compare for '$a' and '$b' (see: dbbench list)"
335}
336
337cmd_list() {
338 [ -d "$RESULTS" ] || { echo "no results yet ($RESULTS)"; return 0; }
339 ls -1 "$RESULTS"/*.json 2>/dev/null | sort -r | while read -r f; do
340 jq -r '[.created, .label, .kind, .git.commit, "py\(.runtime.python) gil=\(.runtime.gil_enabled) jit=\(.runtime.jit_enabled)",
341 (.http // empty | "\(.server) w=\(.workers) rows=\(.rows)")] | join(" ")' "$f"
342 done
343}
344
345cmd_all() {
346 local label="run" a=("$@") i
347 for ((i=0; i<${#a[@]}; i++)); do [ "${a[$i]}" = "--label" ] && label="${a[$((i+1))]}"; done
348 # storage takes --sizes/--repeat, http takes the rest: split what each understands
349 local -a s=(--label "$label") h=(--label "$label")
350 while [ $# -gt 0 ]; do case "$1" in
351 --label) shift 2;; --python) s+=("$1" "$2"); h+=("$1" "$2"); shift 2;;
352 --sizes) s+=("$1" "$2"); shift 2;; --repeat) s+=("$1" "$2"); h+=("$1" "$2"); shift 2;;
353 *) h+=("$1" "$2"); shift 2;; esac; done
354 cmd_storage "${s[@]}"; echo; cmd_http "${h[@]}"
355}
356
357main() {
358 local c="${1:-}"; [ $# -gt 0 ] && shift
359 case "$c" in
360 check) cmd_check "$@";; storage) cmd_storage "$@";; http) cmd_http "$@";;
361 all) cmd_all "$@";; compare) cmd_compare "$@";; list) cmd_list "$@";;
362 ""|-h|--help|help) sed -n '2,24p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//';;
363 *) die "unknown command '$c' (try: dbbench help)";;
364 esac
365}
366main "$@"