Skip to content

Commit 9a0a85a

Browse files
committed
feat(bench): self-contained Docker Compose setup
Build benchmark binary inside container via multi-stage Dockerfile. All-in-one: docker compose run bench.
1 parent 2a0af04 commit 9a0a85a

File tree

3 files changed

+79
-16
lines changed

3 files changed

+79
-16
lines changed

bench/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM haskell:9.6.3 AS build
2+
3+
WORKDIR /src
4+
5+
# Copy cabal file first for dependency caching
6+
COPY simplexmq.cabal cabal.project* ./
7+
RUN cabal update && cabal build --only-dependencies -f server_postgres smp-server-bench || true
8+
9+
# Copy full source
10+
COPY . .
11+
RUN cabal build -f server_postgres smp-server-bench \
12+
&& cp $(cabal list-bin -f server_postgres smp-server-bench) /usr/local/bin/smp-server-bench
13+
14+
FROM debian:bookworm-slim
15+
16+
RUN apt-get update && apt-get install -y --no-install-recommends \
17+
libgmp10 libpq5 libffi8 zlib1g ca-certificates \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
COPY --from=build /usr/local/bin/smp-server-bench /usr/local/bin/smp-server-bench
21+
COPY tests/fixtures /app/tests/fixtures
22+
23+
WORKDIR /app
24+
25+
ENTRYPOINT ["smp-server-bench"]

bench/docker-compose.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ services:
55
POSTGRES_USER: smp
66
POSTGRES_DB: smp_bench
77
POSTGRES_HOST_AUTH_METHOD: trust
8-
ports:
9-
- "15432:5432"
108
volumes:
119
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
1210
- pgdata:/var/lib/postgresql/data
@@ -16,5 +14,33 @@ services:
1614
timeout: 5s
1715
retries: 10
1816

17+
bench:
18+
build:
19+
context: ..
20+
dockerfile: bench/Dockerfile
21+
depends_on:
22+
postgres:
23+
condition: service_healthy
24+
environment:
25+
BENCH_PG: "postgresql://smp@postgres/smp_bench"
26+
BENCH_CLIENTS: "${BENCH_CLIENTS:-5000}"
27+
BENCH_MINUTES: "${BENCH_MINUTES:-5}"
28+
command:
29+
- "--pg"
30+
- "postgresql://smp@postgres/smp_bench"
31+
- "--clients"
32+
- "${BENCH_CLIENTS:-5000}"
33+
- "--minutes"
34+
- "${BENCH_MINUTES:-5}"
35+
- "--timeseries"
36+
- "/results/timeseries.csv"
37+
- "+RTS"
38+
- "-N"
39+
- "-A16m"
40+
- "-T"
41+
- "-RTS"
42+
volumes:
43+
- ./results:/results
44+
1945
volumes:
2046
pgdata:

bench/run.sh

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,59 @@
22
set -e
33
cd "$(dirname "$0")"
44

5-
mkdir -p tmp
5+
mkdir -p results
66

77
reset_db() {
88
docker compose down -v 2>/dev/null || true
9-
docker compose up -d --wait
9+
docker compose up -d --wait postgres
1010
echo "PostgreSQL ready."
1111
}
1212

1313
if [ "$1" = "--compare-rts" ]; then
1414
shift
15+
docker compose build bench
1516
for label_flags in \
16-
"default:-N -A16m -s" \
17-
"F1.2:-N -A16m -F1.2 -s" \
18-
"F1.5:-N -A16m -F1.5 -s" \
19-
"A4m:-N -A4m -s" \
20-
"A4m-F1.2:-N -A4m -F1.2 -s" \
21-
"compact:-N -A16m -c -s" \
22-
"nonmoving:-N -A16m -xn -s"; do
17+
"default:-N -A16m -T" \
18+
"F1.2:-N -A16m -F1.2 -T" \
19+
"F1.5:-N -A16m -F1.5 -T" \
20+
"A4m:-N -A4m -T" \
21+
"A4m-F1.2:-N -A4m -F1.2 -T" \
22+
"compact:-N -A16m -c -T" \
23+
"nonmoving:-N -A16m -xn -T"; do
2324
label="${label_flags%%:*}"
2425
flags="${label_flags#*:}"
2526
echo ""
2627
echo "=========================================="
2728
echo " RTS config: $label ($flags)"
2829
echo "=========================================="
2930
reset_db
30-
cabal run smp-server-bench -- \
31-
--timeseries "bench-${label}.csv" \
31+
docker compose run --rm \
32+
-e BENCH_CLIENTS="${BENCH_CLIENTS:-1000}" \
33+
-e BENCH_MINUTES="${BENCH_MINUTES:-2}" \
34+
bench \
35+
--pg "postgresql://smp@postgres/smp_bench" \
3236
--clients "${BENCH_CLIENTS:-1000}" \
3337
--minutes "${BENCH_MINUTES:-2}" \
38+
--timeseries "/results/bench-${label}.csv" \
3439
"$@" \
3540
+RTS $flags -RTS
3641
done
3742
echo ""
38-
echo "Done. CSV files: bench-*.csv"
39-
else
43+
echo "Done. Results in bench/results/"
44+
elif [ "$1" = "--local" ]; then
45+
# Run natively (not in container) — requires local Postgres
46+
shift
4047
reset_db
41-
cabal run smp-server-bench -- \
48+
cabal run smp-server-bench -f server_postgres -- \
49+
--pg "postgresql://smp@localhost:15432/smp_bench" \
4250
--clients "${BENCH_CLIENTS:-5000}" \
4351
--minutes "${BENCH_MINUTES:-5}" \
4452
"$@" \
4553
+RTS -N -A16m -s -RTS
54+
else
55+
# Run fully in containers
56+
reset_db
57+
docker compose run --rm bench "$@"
4658
fi
4759

4860
docker compose down

0 commit comments

Comments
 (0)