Skip to content

bench: add metrics benchmarking suite for ClickHouse and PostgreSQL - #736

Merged
alexluong merged 2 commits into
metricsfrom
metrics-bench
Mar 13, 2026
Merged

bench: add metrics benchmarking suite for ClickHouse and PostgreSQL#736
alexluong merged 2 commits into
metricsfrom
metrics-bench

Conversation

@alexluong

@alexluong alexluong commented Mar 8, 2026

Copy link
Copy Markdown
Collaborator

Benchmarks QueryEventMetrics / QueryAttemptMetrics against PG and CH.

Dockerized setup with deterministic seeding, shared test cases across backends, single-iteration and sustained run modes via Makefile.

Test Setup

M1 Pro, 2 CPU per container. ~10M events, ~12.6M attempts (~22.6M total rows). March 2026.

Config PG (4GB) PG (8GB) CH (8GB)
Container postgres:16-alpine postgres:16-alpine clickhouse-server:24
Memory 4GB 8GB (shared_buffers=2GB, work_mem=512MB) 8GB (max_memory_usage=6GB)
CPUs 2 2 2 (max_threads=2)
Storage ~2GB ~2GB ~381MB (~5x smaller)
Seed time ~7min ~7min ~instant (OPTIMIZE ~1min)

Data: 2 tenants (tenant_0 90%, tenant_1 10%), 500 destinations, 3 topics, events spread across Jan 2000, chained retries (1 event → 1-4 attempts), 0.5% permanently failed.

Results — Single Iteration (benchtime=1x)

Event Metrics (~9M rows for tenant_0)

Benchmark PG CH CH vs PG
CountAll 770ms 695ms 1.1x faster
CountByTopic 1.21s 1.05s 1.2x faster
CountByDestination 1.19s 745ms 1.6x faster
Hourly_1Day 46ms 19ms 2.4x faster
Hourly_1Week 386ms 95ms 4.1x faster
Daily_1Month 1.41s 658ms 2.1x faster
FilterByTopic 709ms 438ms 1.6x faster
SmallTenant 323ms 209ms 1.5x faster

Attempt Metrics (~10M rows for tenant_0)

Benchmark PG CH CH vs PG
CountAll 1.11s 794ms 1.4x faster
CountByTopic 1.79s 1.29s 1.4x faster
CountByDestination 1.77s 966ms 1.8x faster
CountByStatus 1.72s 1.35s 1.3x faster
Hourly_1Day 73ms 22ms 3.3x faster
Hourly_1Week 475ms 118ms 4.0x faster
Daily_1Month 1.99s 804ms 2.5x faster
AllMeasures 1.77s 3.30s 0.5x (PG wins)
FilterByStatus 86ms 435ms 0.2x (PG wins)
FilterByTopic 1.24s 569ms 2.2x faster
MultiDimension 2.32s 1.39s 1.7x faster
SmallTenant 789ms 505ms 1.6x faster

Results — Sustained Load (benchtime=10s, count=3)

CH 8GB vs PG 8GB — Head-to-Head (Attempts)

Benchmark PG 8GB CH 8GB CH vs PG
CountAll 1.23s ~1.0s 1.2x faster
CountByTopic 3.46s 1.37s 2.5x faster
CountByDestination 3.22s 1.0s 3.2x faster
CountByStatus 3.21s 1.68s 1.9x faster
Hourly_1Day 54ms 20ms 2.7x faster
Hourly_1Week 368ms 119ms 3.1x faster
Daily_1Month 2.89s 855ms 3.4x faster
AllMeasures 3.10s 2.59s 1.2x faster
FilterByStatus 141ms 413ms 0.3x (PG wins)
FilterByTopic 617ms 583ms ~same
MultiDimension 4.93s 1.54s 3.2x faster
SmallTenant 1.06s 359ms 3.0x faster

PG 4GB — Sustained Degradation

PG at 4GB degraded significantly under sustained load (cache thrashing). Heavy queries drifted +29% to +104% across runs. At 8GB PG stabilized with 2.6-5.9x improvement on heavy queries.

Key Findings

  1. CH is rock stable under sustained load. No query drifted more than ~10% across 3 runs.
  2. CH wins 1.2-4x on most queries at matched resources (2 CPU, 8GB). Advantage grows with wider time ranges and more dimensions.
  3. PG wins on FilterByStatus — composite index enables index-only scan. PG 141ms vs CH 413ms.
  4. AllMeasures is CH's weakest queryuniqExactIf dedup tax from ReplacingMergeTree. Still competitive under sustained load.
  5. Storage: CH is ~5x smaller — ~381MB vs ~2GB for ~22.6M rows.
  6. PG is extremely memory-sensitive. 4GB → 8GB improved heavy queries 3-6x. CH consistent regardless.
  7. Time-range selectivity is CH's biggest win — partition pruning + columnar storage excels at narrow scans.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Mar 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
outpost-docs Ready Ready Preview, Comment Mar 10, 2026 6:59pm
outpost-website Ready Ready Preview, Comment Mar 10, 2026 6:59pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – outpost-website March 8, 2026 20:00 Inactive
@vercel
vercel Bot temporarily deployed to Preview – outpost-docs March 8, 2026 20:01 Inactive
alexluong and others added 2 commits March 11, 2026 01:54
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…anularity, filters

Migrate bench suite to current metrics API (TimeRange, tenant via filters)
and add bench cases for rate measures, multi-value granularities (2d/w/M),
new dimensions (code, attempt_number), and new filters (code, manual,
attempt_number, multi-filter).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
vercel Bot temporarily deployed to Preview – outpost-website March 10, 2026 18:59 Inactive
@vercel
vercel Bot temporarily deployed to Preview – outpost-docs March 10, 2026 18:59 Inactive
@alexluong
alexluong merged commit 26cd1d6 into metrics Mar 13, 2026
4 checks passed
@alexluong
alexluong deleted the metrics-bench branch March 13, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants