Monorepo for Tangled
tangled.org
1#!/usr/bin/env bash
2# quick boot-time benchmark for the spindle nixos microvm.
3# boots N times running a trivial command, reports wall-clock + systemd-analyze.
4# needs: sudo modprobe vhost_vsock
5set -euo pipefail
6
7N="${1:-5}"
8cd "$(git rev-parse --show-toplevel)"
9
10strip_ansi() { sed -E "s/$(printf '\033')\[[0-9;]*[a-zA-Z]//g; s/$(printf '\033')\([a-zA-Z]//g"; }
11
12echo ">>> building runner + image"
13nix develop --command go build -o spindle/spindle-microvm-run ./cmd/spindle-microvm-run
14TARBALL=$(nix build .#spindle-nixos-image-tarball --no-link --print-out-paths)
15
16WORK=$(mktemp -d -t spindle-bench-XXXXXX)
17trap 'chmod -R +w "$WORK" 2>/dev/null || true; rm -rf "$WORK"' EXIT
18mkdir -p "$WORK/image"
19tar -C "$WORK/image" -xzf "$TARBALL"
20SPEC="$WORK/image/spec.json"
21
22echo ">>> systemd-analyze breakdown"
23spindle/spindle-microvm-run --image-spec "$SPEC" --work-dir "$WORK/analyze" --exec-timeout 60s -- \
24 /run/current-system/sw/bin/systemd-analyze time 2>/dev/null | strip_ansi | grep -i startup || true
25
26echo ">>> $N timed boot+exec(true) runs"
27total=0
28for i in $(seq 1 "$N"); do
29 start=$EPOCHREALTIME
30 spindle/spindle-microvm-run --image-spec "$SPEC" --work-dir "$WORK/run$i" --exec-timeout 60s -- \
31 /run/current-system/sw/bin/true >/dev/null 2>&1
32 end=$EPOCHREALTIME
33 ms=$(( (${end%.*} - ${start%.*}) * 1000 + (10#${end#*.} - 10#${start#*.}) / 1000 ))
34 echo " run $i: ${ms}ms"
35 total=$((total + ms))
36 rm -rf "$WORK/run$i"
37done
38echo ">>> mean wall-clock: $((total / N))ms over $N runs"