A benchmark to tell how approximation is helping. Current status: a benchmark over sketch instance and over (selected) data processing system.
The benchmark has two levels:
- Sketch benchmark: one sketch instance on data the benchmark generates. It compares sketches, libraries and configurations on throughput, latency, memory and accuracy.
- System benchmark: the same queries on real data processing systems, exact and approximate. It compares answers, time, CPU and memory.
cargo build --releaseThe binary is target/release/approxbench.
Compares: how fast a HyperLogLog from asap_sketchlib takes 1M Zipf keys, and how far its distinct count is from the exact count.
./target/release/approxbench sketchbench \
--variant hyperloglog --library asap_sketchlib --config 'lg_k=14' \
--dataset zipf --size 1000000 --zipf-s 1.1 --cardinality 100000 --dtype i64 \
--runs 10 --warmup-runs 3 \
--operations insert --metrics throughput,memory --flat --pretty-print
./target/release/approxbench sketchbench \
--variant hyperloglog --library asap_sketchlib --config 'lg_k=14' \
--dataset zipf --size 1000000 --zipf-s 1.1 --cardinality 100000 --dtype i64 \
--operations query --metrics accuracy --flat --pretty-printWhat to expect: one JSON record per command. The first has insert_throughput_items_per_sec (about 3×10^8 items/s on our machine) and memory_bytes (16400). The second has query_accuracy with estimate, truth and relative_error (about 0.006).
| Flag | Meaning |
|---|---|
--variant, --library |
which sketch, from which library; --list-impls lists every pair |
--config |
the sketch's parameters; hyperloglog takes lg_k, log2 of the register count |
--dataset, --size, --zipf-s, --cardinality |
the generated data: distribution, row count, skew, key space |
--dtype |
item type: i64, u64, f64 or string |
--runs, --warmup-runs |
measured runs, and runs discarded before them |
--operations × --metrics |
crossed: every operation is measured on every metric; a pair that means nothing (accuracy of insert) is refused |
--flat, --pretty-print |
one flat JSON record, printed on several lines |
Compares: the cost of Hydra with UnivMon cells, which keeps one UnivMon for every subset of a record's labels, on insert and on merging 8 shards.
./target/release/approxbench sketchbench \
--variant hydra-univmon-cardinality --library asap_sketchlib \
--spec configs/datagen/hydra_univmon_columns.yaml --dtype i64 \
--config "rows=2 cols=8 cell_heap_size=1000 cell_sketch_row=5 cell_sketch_col=2048 cell_layer_size=8" \
--operations insert,merge --metrics throughput \
--merge-shards 8 --runs 5 --warmup-runs 2 --flat --pretty-printWhat to expect: insert_throughput_items_per_sec (about 2.3×10^5 records/s), merge_wall_time_ms and merge_folds_per_sec for folding 8 shards into one. Use --operations query --metrics accuracy for the per-group error, and --library polars for the exact answer to the same question.
| Flag | Meaning |
|---|---|
--spec |
a YAML table description instead of --dataset: label columns, then the value column |
--config |
rows, cols: the Hydra grid; cell_*: each UnivMon cell |
--merge-shards, --merge-split |
how many shards merge folds, and how the stream is cut (contiguous or interleaved) |
--group-columns |
which label columns a group is taken over; default 0 |
Compares: the 43 queries of ClickBench (each engine's queries.sql, one query per line), exact on DuckDB and ClickHouse, and 7 of them approximate through PilotDB's sampling over DuckDB, against DuckDB's exact answers. With POSTGRESQL_CONNECTION and DRUID_URL set, the same run adds TimescaleDB (exact, and its COUNT(DISTINCT) variant) and Druid (exact, and its approximate defaults).
APPROXBENCH=$PWD/target/release/approxbench \
ENGINE_CPUS=0-15 THREADS=16 PILOTDB_PYTHON=~/pilotdb/venv/bin/python \
scripts/one-shot-clickbench.sh ~/ClickBench /data/clickbench runs/clickbenchWhat to expect: runs/clickbench/one-shot-summary.md (and .csv), one row per configuration and query, with its accuracy against duckdb/exact and its speedup over each exact run. On a 64-core machine with the data in memory, this takes about 15 minutes.
Before the run:
- Get the data: clone ClickBench, and download
hits.parquet(about 14 GB) into the data directory. - Install DuckDB and PilotDB:
scripts/install-duckdb.sh <dir>putsduckdbin<dir>; put it onPATHor setDUCKDBto it.scripts/install-pilotdb.sh <dir>prints thePILOTDB_PYTHONto use. PilotDB also needslibodbc.so.2(Ubuntu:apt install libodbc2). - Start ClickHouse: a ClickHouse server whose
user_files_pathcontains the data directory, since it loadshits.parquetwithfile(). SetCLICKHOUSE_URLif it does not listen onhttp://127.0.0.1:8123. (scripts/extbench-up.sh clickhouse upstarts one in Docker, but does not mount the data directory, so it cannot readhits.parquet.) - Druid and TimescaleDB, if measured:
scripts/extbench-up-druid.sh up ...orscripts/extbench-up-timescaledb.sh up ..., withDATA_DIRECTORYset to the data directory so the server can readhits.parquet. - Point to
approxbench: put it onPATH, or setAPPROXBENCHto it, as the command above does. - Skip an engine: set its variable empty, such as
CLICKHOUSE_URL=orPILOTDB_PYTHON=. Druid and TimescaleDB run only whenDRUID_URLorPOSTGRESQL_CONNECTIONis set. - All options:
scripts/one-shot-workload.sh --help. That script also runs any other workload file the same way.
The use-case study has five use cases. In each one, an application makes decisions from query answers. The five are: 1 DDoS detection, 2 resource scaling, 3 video experience, 4 canary release, 5 rate limiting (pages). This example runs use case 5, rate limiting, on VictoriaMetrics and ASAPQuery-backend, and compares their answers and the decisions taken from them. To run another use case, change 5 to its number.
python3 scripts/use_cases/run_use_case_on_systems.py 5 \
--victoriametrics ~/victoriametrics/victoria-metrics-prod \
--backend-dir ~/asapquery-backend/target/releaseWhat to expect: one directory per arm under target/grafana-data/phase3/runs/ (use case 5 has 4 arms, one per error target), which the phase 3 Grafana dashboards read (tools/grafana/run.sh --phase 3). It also prints, per arm, how many queries the backend supports and how many failed. Use case 5 takes about 10 minutes.
Before the run:
- Build planeval: the script uses
planevalto compute the exact answers and score both systems.cargo build --release -p system-bench --features planeval. - Download VictoriaMetrics v1.154.1:
mkdir -p ~/victoriametrics && curl -L https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.154.1/victoria-metrics-linux-amd64-v1.154.1.tar.gz | tar xz -C ~/victoriametrics - Build ASAPQuery-backend:
scripts/extbench-up-asapquery-backend.sh build ~/asapquery-backendclones it at the pinned commit and builds it. - No servers to start: the script starts and stops both systems itself.
- All options:
python3 scripts/use_cases/run_use_case_on_systems.py --help.
The Quickstart above runs one example of each level. For more:
- Sketch benchmark, step by step: workflow.
- System benchmark: system-bench.
- Use-case study: usecase-study.
Check this developer_guide about how to add a sketch instance, ground truth, data generation, a system or a use case. Terms used across the repository are in terminology.
Some crate-oriented design thought is as followed, if anyone is interested:
Shared by both levels:
- aqpbm-core: metrics, ground truth, result records and the harness.
- aqpbm-datagen: data generation.
- aqpbm-cli: the
approxbenchcommand.
Operator level:
- sketch-bench: sketch wrappers, rows and the registry.
System level:
- system-bench: adapters for external systems and the registry of systems.
- planeval: part of
system-bench; runs ASAPPlanner's plans in process. - Capability files: part of
system-bench; what ClickHouse and VictoriaMetrics can run. - Harness: part of
aqpbm-core; how every system-level measurement is taken.
Use-case study:
- usecase-study: the five use cases' workloads and the scoring of answers.
- Use case pages: each use case's queries, rules and results.