askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
object_modes.sh · 2.4 KB · 32 lines
| 1 | #!/bin/bash |
| 2 | # How much does an HTTP call to an object cost under each execution mode? |
| 3 | # in-process (default) | DBBASIC_OBJECT_TIMEOUT_SECONDS=5 (spawn per call, the documented production setting) |
| 4 | # | timeout + DBBASIC_WORKER_POOL_SIZE=N (warm pool) |
| 5 | # usage: object_modes.sh [PYTHON] -- needs oha. Uses a throwaway data dir. |
| 6 | set -u |
| 7 | PY="${1:-$(cd "$(dirname "$0")/../../.." && pwd)/.venv-jit/bin/python}" |
| 8 | REPO="$(cd "$(dirname "$0")/../../.." && pwd)" |
| 9 | run_mode() { # label, N-requests, conns, env... |
| 10 | local label="$1" n="$2" c="$3"; shift 3 |
| 11 | local tmp port; tmp=$(mktemp -d); port=$((20000 + RANDOM % 20000)) |
| 12 | mkdir -p "$tmp/objects" "$tmp/data" |
| 13 | cat > "$tmp/objects/bench_hello.py" <<'PYEOF' |
| 14 | def GET(request): |
| 15 | return {"status": "ok", "hello": "world"} |
| 16 | PYEOF |
| 17 | (cd "$REPO" && exec env DBBASIC_OBJECTS_DIR="$tmp/objects" DBBASIC_DATA_DIR="$tmp/data" DBBASIC_ADMIN_TOKEN=t DBBASIC_MAX_CONCURRENT_EXECUTIONS=0 "$@" \ |
| 18 | "$PY" -m uvicorn object_server:app --host 127.0.0.1 --port "$port" --log-level warning --no-access-log >"$tmp/log" 2>&1) & |
| 19 | echo $! >"$tmp/pid" |
| 20 | for _ in $(seq 40); do curl -sf "http://127.0.0.1:$port/health" >/dev/null && break; sleep 0.5; done |
| 21 | local code; code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Authorization: Token t' "http://127.0.0.1:$port/objects/bench_hello") |
| 22 | if [ "$code" != 200 ]; then echo "$label: object call returned $code"; head -c 300 "$tmp/log"; kill "$(cat "$tmp/pid")"; return; fi |
| 23 | oha -n "$n" -c "$c" --no-tui --output-format json -H 'Authorization: Token t' "http://127.0.0.1:$port/objects/bench_hello" | |
| 24 | jq -r --arg l "$label" --arg c "$c" '"\($l) conns=\($c) \(.summary.requestsPerSec|floor) req/s p50 \(.latencyPercentiles.p50*1000|.*10|floor/10) ms p99 \(.latencyPercentiles.p99*1000|.*10|floor/10) ms ok=\(.statusCodeDistribution["200"]//0)/\(.summary.total? // "?")"' |
| 25 | kill "$(cat "$tmp/pid")" 2>/dev/null; wait 2>/dev/null; rm -rf "$tmp" |
| 26 | } |
| 27 | run_mode "in-process (default) " 3000 1 |
| 28 | run_mode "in-process (default) " 3000 8 |
| 29 | run_mode "timeout=5, spawn per call " 40 1 DBBASIC_OBJECT_TIMEOUT_SECONDS=5 |
| 30 | run_mode "timeout=5, spawn per call " 80 8 DBBASIC_OBJECT_TIMEOUT_SECONDS=5 |
| 31 | run_mode "timeout=5 + warm pool of 4 " 3000 1 DBBASIC_OBJECT_TIMEOUT_SECONDS=5 DBBASIC_WORKER_POOL_SIZE=4 |
| 32 | run_mode "timeout=5 + warm pool of 4 " 3000 8 DBBASIC_OBJECT_TIMEOUT_SECONDS=5 DBBASIC_WORKER_POOL_SIZE=4 |