diff --git a/bench/Dockerfile b/bench/Dockerfile new file mode 100644 index 000000000..1bdcc1290 --- /dev/null +++ b/bench/Dockerfile @@ -0,0 +1,25 @@ +FROM haskell:9.6.3 AS build + +WORKDIR /src + +# Copy cabal file first for dependency caching +COPY simplexmq.cabal cabal.project* ./ +RUN cabal update && cabal build --only-dependencies -f server_postgres smp-server-bench || true + +# Copy full source +COPY . . +RUN cabal build -f server_postgres smp-server-bench \ + && cp $(cabal list-bin -f server_postgres smp-server-bench) /usr/local/bin/smp-server-bench + +FROM debian:bookworm-slim + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libgmp10 libpq5 libffi8 zlib1g ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build /usr/local/bin/smp-server-bench /usr/local/bin/smp-server-bench +COPY tests/fixtures /app/tests/fixtures + +WORKDIR /app + +ENTRYPOINT ["smp-server-bench"] diff --git a/bench/docker-compose.yml b/bench/docker-compose.yml index ce7f16ec4..92aed6b52 100644 --- a/bench/docker-compose.yml +++ b/bench/docker-compose.yml @@ -5,8 +5,6 @@ services: POSTGRES_USER: smp POSTGRES_DB: smp_bench POSTGRES_HOST_AUTH_METHOD: trust - ports: - - "15432:5432" volumes: - ./init.sql:/docker-entrypoint-initdb.d/init.sql - pgdata:/var/lib/postgresql/data @@ -16,5 +14,33 @@ services: timeout: 5s retries: 10 + bench: + build: + context: .. + dockerfile: bench/Dockerfile + depends_on: + postgres: + condition: service_healthy + environment: + BENCH_PG: "postgresql://smp@postgres/smp_bench" + BENCH_CLIENTS: "${BENCH_CLIENTS:-5000}" + BENCH_MINUTES: "${BENCH_MINUTES:-5}" + command: + - "--pg" + - "postgresql://smp@postgres/smp_bench" + - "--clients" + - "${BENCH_CLIENTS:-5000}" + - "--minutes" + - "${BENCH_MINUTES:-5}" + - "--timeseries" + - "/results/timeseries.csv" + - "+RTS" + - "-N" + - "-A16m" + - "-T" + - "-RTS" + volumes: + - ./results:/results + volumes: pgdata: diff --git a/bench/run.sh b/bench/run.sh index 3f4f9e671..f62160b51 100755 --- a/bench/run.sh +++ b/bench/run.sh @@ -2,24 +2,25 @@ set -e cd "$(dirname "$0")" -mkdir -p tmp +mkdir -p results reset_db() { docker compose down -v 2>/dev/null || true - docker compose up -d --wait + docker compose up -d --wait postgres echo "PostgreSQL ready." } if [ "$1" = "--compare-rts" ]; then shift + docker compose build bench for label_flags in \ - "default:-N -A16m -s" \ - "F1.2:-N -A16m -F1.2 -s" \ - "F1.5:-N -A16m -F1.5 -s" \ - "A4m:-N -A4m -s" \ - "A4m-F1.2:-N -A4m -F1.2 -s" \ - "compact:-N -A16m -c -s" \ - "nonmoving:-N -A16m -xn -s"; do + "default:-N -A16m -T" \ + "F1.2:-N -A16m -F1.2 -T" \ + "F1.5:-N -A16m -F1.5 -T" \ + "A4m:-N -A4m -T" \ + "A4m-F1.2:-N -A4m -F1.2 -T" \ + "compact:-N -A16m -c -T" \ + "nonmoving:-N -A16m -xn -T"; do label="${label_flags%%:*}" flags="${label_flags#*:}" echo "" @@ -27,22 +28,33 @@ if [ "$1" = "--compare-rts" ]; then echo " RTS config: $label ($flags)" echo "==========================================" reset_db - cabal run smp-server-bench -- \ - --timeseries "bench-${label}.csv" \ + docker compose run --rm \ + -e BENCH_CLIENTS="${BENCH_CLIENTS:-1000}" \ + -e BENCH_MINUTES="${BENCH_MINUTES:-2}" \ + bench \ + --pg "postgresql://smp@postgres/smp_bench" \ --clients "${BENCH_CLIENTS:-1000}" \ --minutes "${BENCH_MINUTES:-2}" \ + --timeseries "/results/bench-${label}.csv" \ "$@" \ +RTS $flags -RTS done echo "" - echo "Done. CSV files: bench-*.csv" -else + echo "Done. Results in bench/results/" +elif [ "$1" = "--local" ]; then + # Run natively (not in container) — requires local Postgres + shift reset_db - cabal run smp-server-bench -- \ + cabal run smp-server-bench -f server_postgres -- \ + --pg "postgresql://smp@localhost:15432/smp_bench" \ --clients "${BENCH_CLIENTS:-5000}" \ --minutes "${BENCH_MINUTES:-5}" \ "$@" \ +RTS -N -A16m -s -RTS +else + # Run fully in containers + reset_db + docker compose run --rm bench "$@" fi docker compose down