From edfa71ce7cdd5fc66dbd7b862f7770b0c6d981b6 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 26 Jun 2026 14:28:05 -0400 Subject: [PATCH] Add script to reproduce threading performance report results Adds `reproduce_threading_report.sh` to run the WeaselDB server and load tester configuration described in `threading_performance_report.md`. Improvements over the original draft: - Validates the build directory, config file, and required binaries before starting, and expects to be run from the project root. - Wraps server shutdown and log printing in an EXIT/INT/TERM trap so the server is always cleaned up, even if the script is interrupted or the load tester fails. - Makes the `ulimit -n` increase best-effort instead of fatal. - Uses the existing `DURATION` variable consistently in the load tester invocation. - Adds a final check that the unix socket was created before launching the load tester. - Uses 2 connect threads on the client, which is sufficient for establishing 2000 connections over the 30-second run. --- reproduce_threading_report.sh | 89 +++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 reproduce_threading_report.sh diff --git a/reproduce_threading_report.sh b/reproduce_threading_report.sh new file mode 100755 index 0000000..5e25cf8 --- /dev/null +++ b/reproduce_threading_report.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# Reproduce the threading performance report results. +# Run from the project root, e.g.: +# ./reproduce_threading_report.sh +set -euo pipefail + +BUILD_DIR="build" +CONFIG="test_benchmark_config.toml" +DURATION=30 + +if [ ! -d "$BUILD_DIR" ]; then + echo "Error: build directory '$BUILD_DIR' not found. Build the project first." >&2 + exit 1 +fi + +if [ ! -f "$CONFIG" ]; then + echo "Error: config '$CONFIG' not found. Run this script from the project root." >&2 + exit 1 +fi + +if [ ! -x "$BUILD_DIR/weaseldb" ] || [ ! -x "$BUILD_DIR/load_tester" ]; then + echo "Error: required binaries not found in '$BUILD_DIR'. Build the project first." >&2 + exit 1 +fi + +cd "$BUILD_DIR" + +# Increase file descriptor limit for high concurrency. Best-effort only: +# it may fail if the hard limit is lower, especially in containers. +ulimit -n 65536 2>/dev/null || echo "Warning: could not raise ulimit -n (continuing)" >&2 + +# Clean up any leftover socket or server log from a previous run +rm -f weaseldb.sock server.log + +SERVER_PID="" + +cleanup() { + if [ -n "$SERVER_PID" ] && kill -0 "$SERVER_PID" 2>/dev/null; then + echo "" + echo "=== Stopping server ===" + kill "$SERVER_PID" 2>/dev/null || true + wait "$SERVER_PID" 2>/dev/null || true + fi + echo "=== Server log tail ===" + tail -50 server.log 2>/dev/null || true +} +trap cleanup EXIT INT TERM + +echo "=== Starting WeaselDB server ===" +./weaseldb --config "../$CONFIG" > server.log 2>&1 & +SERVER_PID=$! + +echo "Server PID: $SERVER_PID" + +# Wait for server to be ready (unix socket created) +for i in {1..30}; do + if [ -S weaseldb.sock ]; then + echo "Server ready after $((i * 100))ms" + break + fi + if ! kill -0 "$SERVER_PID" 2>/dev/null; then + echo "Server died unexpectedly" + cat server.log + exit 1 + fi + sleep 0.1 +done + +if [ ! -S weaseldb.sock ]; then + echo "Error: server failed to create socket within 3 seconds" >&2 + exit 1 +fi + +echo "=== Server log (first lines) ===" +head -30 server.log + +echo "" +echo "=== Running load tester ===" +./load_tester \ + --unix-socket weaseldb.sock \ + --concurrency 2000 \ + --requests-per-conn 500 \ + --connect-threads 2 \ + --network-threads 10 \ + --duration "$DURATION" \ + --stats-interval 1 + +echo "" +echo "=== Load test complete ==="