Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions cmd/bench/metrics/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Metrics Benchmarks Makefile
# Usage: cd cmd/bench/metrics && make <target>

OUTPOST_ROOT := $(shell git rev-parse --show-toplevel)
PG_URL := postgres://outpost:outpost@localhost:5488/bench?sslmode=disable
CH_ADDR := localhost:9009
CH_DB := bench
PG_ROWS := 10000000
CH_ROWS := 10000000

# ── Infra ────────────────────────────────────────────────────────────────────

up/pg:
docker compose -f pg/docker-compose.yml up -d

up/ch:
docker compose -f ch/docker-compose.yml up -d

up: up/pg up/ch

down/pg:
docker compose -f pg/docker-compose.yml down -v

down/ch:
docker compose -f ch/docker-compose.yml down -v

down: down/pg down/ch

# ── Migrations ───────────────────────────────────────────────────────────────

migrate/pg:
cd $(OUTPOST_ROOT) && BENCH_PG_URL="$(PG_URL)" \
go test -run='^$$' -bench=BenchmarkPG -benchtime=1x ./cmd/bench/metrics/

migrate/ch:
cd $(OUTPOST_ROOT) && BENCH_CH_ADDR="$(CH_ADDR)" BENCH_CH_DB="$(CH_DB)" \
go test -run='^$$' -bench=BenchmarkCH -benchtime=1x ./cmd/bench/metrics/

migrate: migrate/pg migrate/ch

# ── Seeding ──────────────────────────────────────────────────────────────────

seed/pg:
psql "$(PG_URL)" -v ROWS=$(PG_ROWS) -f pg/seed.sql

seed/ch:
clickhouse client --port 9009 --database $(CH_DB) \
--param_rows $(CH_ROWS) < ch/seed.sql

# ── Benchmarks ───────────────────────────────────────────────────────────────

bench/pg:
cd $(OUTPOST_ROOT) && BENCH_PG_URL="$(PG_URL)" \
go test -bench=BenchmarkPG -benchtime=1x -count=1 -timeout=30m ./cmd/bench/metrics/

bench/ch:
cd $(OUTPOST_ROOT) && BENCH_CH_ADDR="$(CH_ADDR)" BENCH_CH_DB="$(CH_DB)" \
go test -bench=BenchmarkCH -benchtime=1x -count=1 -timeout=30m ./cmd/bench/metrics/

bench/pg/sustained:
cd $(OUTPOST_ROOT) && BENCH_PG_URL="$(PG_URL)" \
go test -bench=BenchmarkPG -benchtime=10s -count=3 -timeout=30m ./cmd/bench/metrics/

bench/ch/sustained:
cd $(OUTPOST_ROOT) && BENCH_CH_ADDR="$(CH_ADDR)" BENCH_CH_DB="$(CH_DB)" \
go test -bench=BenchmarkCH -benchtime=10s -count=3 -timeout=30m ./cmd/bench/metrics/

bench: bench/pg bench/ch

# ── Full workflow ────────────────────────────────────────────────────────────

setup/pg: up/pg migrate/pg seed/pg
setup/ch: up/ch migrate/ch seed/ch
setup: setup/pg setup/ch

reset/pg: down/pg up/pg migrate/pg seed/pg
reset/ch: down/ch up/ch migrate/ch seed/ch

.PHONY: up/pg up/ch up down/pg down/ch down \
migrate/pg migrate/ch migrate \
seed/pg seed/ch \
bench/pg bench/ch bench/pg/sustained bench/ch/sustained bench \
setup/pg setup/ch setup reset/pg reset/ch
63 changes: 63 additions & 0 deletions cmd/bench/metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Metrics Benchmarks

Benchmarks `QueryEventMetrics` / `QueryAttemptMetrics` against PostgreSQL and ClickHouse.

Shared test cases in `bench_test.go`, backend-specific setup in `pg_test.go` / `ch_test.go`.

## Quick Start

```bash
cd outpost/cmd/bench/metrics

# ── ClickHouse ───────────────────────────────
make setup/ch # up + migrate + seed (10M)
make bench/ch # single iteration
make bench/ch/sustained # 10s x 3 runs
make down/ch # cleanup

# ── PostgreSQL ───────────────────────────────
make setup/pg # up + migrate + seed (10M)
make bench/pg # single iteration
make bench/pg/sustained # 10s x 3 runs
make down/pg # cleanup

# ── Both ─────────────────────────────────────
make setup # setup both
make bench # bench both
make down # cleanup both
```

### Individual steps

```bash
make up/ch # start container
make migrate/ch # run migrations
make seed/ch # seed data (default 10M, override: make seed/ch CH_ROWS=1000000000)
make bench/ch # run benchmarks
make reset/ch # down + up + migrate + seed (fresh start)
```

Same targets available for `/pg`.

## Structure

```
metrics/
Makefile # all commands
bench_test.go # shared test cases + date ranges + helpers
pg_test.go # PG setup (BENCH_PG_URL)
ch_test.go # CH setup (BENCH_CH_ADDR)
pg/ # PG infra (docker-compose, seed.sql)
ch/ # CH infra (docker-compose, seed.sql, config/)
```

## Data Distribution

Deterministic via modulo arithmetic (identical for both backends):

- **2 tenants** — `tenant_0` (90%), `tenant_1` (10%)
- **500 destinations** — `dest_0` through `dest_499`
- **3 topics** — `order.created`, `order.updated`, `payment.received`
- **Time** — evenly spread across January 2000
- **Attempts** — chained retries (1 event -> 1-4 attempts), 0.5% permanently failed
- 10M events -> ~12.6M attempts (22.6M total rows)
Loading
Loading