Skip to content
Draft
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
2 changes: 2 additions & 0 deletions docs/system-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Not every system supports every measurement:
| `druid` | | yes | |
| `pilotdb` (over DuckDB) | | yes | |
| `victoriametrics` | yes | | |
| `questdb` | yes | | |
| `asapquery-backend` | yes | | |
| `asapquery-precompute-engine` | | | yes |
| `fake` (for tests) | yes | | |
Expand All @@ -38,6 +39,7 @@ approxbench benchmark-external write-throughput --help
What to run comes from a run directory: the workloads, and the plans if a system runs planned queries.
`scripts/plan-suite.sh` prepares a run directory from a suite.
`scripts/one-shot-workload.sh` and `scripts/one-shot-clickbench.sh` prepare one and run every system for one-shot queries.
`scripts/questdb_variants.py` adds QuestDB's variants (native SQL, materialized views, approximate functions) to a run directory.
`scripts/write-throughput-asapquery-precompute-engine.sh` measures the write throughput of an ASAPQuery precompute engine.

## Output
Expand Down
129 changes: 129 additions & 0 deletions scripts/extbench-up-questdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env bash
# Start (or stop) a QuestDB server for
# `approxbench benchmark-external run --engine questdb` on this host: a docker
# container pinned to given cores. The harness reads its cgroup over SSH
# (`--server-ssh-host`, `--server-cgroup-directory`).
#
# scripts/extbench-up-questdb.sh up <data-dir> <cores> <numa-nodes> <http-port> [<name>]
# scripts/extbench-up-questdb.sh down <data-dir> [<name>]
#
# Example: LISTEN_HOST=10.0.0.2 scripts/extbench-up-questdb.sh up /data/run-1/questdb 2,4,6,8 0 19000
#
# Environment:
# LISTEN_HOST address the server listens on (required): a private
# (10/8, 172.16/12, 192.168/16) or loopback address,
# never 0.0.0.0 or a public one: the server has no password
# IMAGE the image, pinned by digest (default: 10.2.0 below)
# QUESTDB_PARALLEL_SQL off (default): each query runs on one thread (parallel
# filter, GROUP BY, window join and Parquet read off), as
# ClickHouse runs with max_threads=1; on: QuestDB's defaults
# MEMORY_LIMIT a docker memory limit such as 32g (default: none)
#
# The server listens on HTTP <http-port> (SQL `/exec`, ILP `/write`), and
# its PostgreSQL wire, ILP TCP and health ports are <http-port>+1, +2 and
# +3 on LISTEN_HOST too. Queries may run 10 minutes (QuestDB's default is 1).
#
# Every start begins from an empty data dir. The script only deletes a data
# dir it created (it holds the marker file .extbench-data-dir). The
# container runs as the invoking user, with no CPU quota.
set -euo pipefail

marker=.extbench-data-dir
# questdb/questdb:10.2.0 (released 2026-11-10), multi-arch index digest.
default_image=questdb/questdb@sha256:bbf5b3cb0dfb08ad667a008dbcc48794bf942d18d1ad832cb6ecb7ff87314694

# Exit 0 when $1 is a private or loopback IPv4 address.
private_address() {
local a b c d
IFS=. read -r a b c d <<<"$1" || return 1
for octet in "$a" "$b" "$c" "$d"; do
[[ "$octet" =~ ^[0-9]+$ ]] && [ "$octet" -le 255 ] || return 1
done
[ "$a" = 10 ] && return 0
[ "$a" = 127 ] && return 0
[ "$a" = 172 ] && [ "$b" -ge 16 ] && [ "$b" -le 31 ] && return 0
[ "$a" = 192 ] && [ "$b" = 168 ] && return 0
return 1
}

# "2,4-6" as "2 4 5 6".
expand_cores() {
local part
for part in ${1//,/ }; do
if [[ "$part" == *-* ]]; then seq "${part%-*}" "${part#*-}"; else echo "$part"; fi
done | tr '\n' ' '
}

action=${1:?up|down}; data_dir=$(realpath -m "${2:?data dir}")

if [ "$action" = down ]; then
name=${3:-extbench-questdb}
docker rm -f "$name" >/dev/null 2>&1 || true
exit 0
fi
[ "$action" = up ] || { echo "unknown action $action" >&2; exit 2; }

cores=${3:?cores}; numa=${4:?numa nodes}; http_port=${5:?http port}
name=${6:-extbench-questdb}
image=${IMAGE:-$default_image}
parallel=${QUESTDB_PARALLEL_SQL:-off}
: "${LISTEN_HOST:?set LISTEN_HOST to a private address}"
private_address "$LISTEN_HOST" || { echo "refused: LISTEN_HOST $LISTEN_HOST is not a private address" >&2; exit 1; }
[[ "$image" == *@sha256:* ]] || { echo "refused: IMAGE must be pinned by digest" >&2; exit 1; }
case "$parallel" in
off) sql_parallel=false ;;
on) sql_parallel=true ;;
*) echo "QUESTDB_PARALLEL_SQL is on or off, not $parallel" >&2; exit 2 ;;
esac

if [ -e "$data_dir" ]; then
[ -f "$data_dir/$marker" ] || { echo "refused: $data_dir exists and was not made by this script" >&2; exit 1; }
docker rm -f "$name" >/dev/null 2>&1 || true
rm -rf "$data_dir"
fi
mkdir -p "$data_dir/root"; touch "$data_dir/$marker"

memory=()
[ -n "${MEMORY_LIMIT:-}" ] && memory=(--memory "$MEMORY_LIMIT" --memory-swap "$MEMORY_LIMIT")
docker rm -f "$name" >/dev/null 2>&1 || true
docker run -d --name "$name" --network host \
--cpuset-cpus "$cores" --cpuset-mems "$numa" --user "$(id -u):$(id -g)" "${memory[@]}" \
-v "$data_dir/root:/var/lib/questdb" \
-e QDB_HTTP_BIND_TO="$LISTEN_HOST:$http_port" \
-e QDB_PG_NET_BIND_TO="$LISTEN_HOST:$((http_port + 1))" \
-e QDB_LINE_TCP_NET_BIND_TO="$LISTEN_HOST:$((http_port + 2))" \
-e QDB_HTTP_MIN_NET_BIND_TO="$LISTEN_HOST:$((http_port + 3))" \
-e QDB_LINE_UDP_ENABLED=false \
-e QDB_TELEMETRY_ENABLED=false \
-e QDB_QUERY_TIMEOUT=10m \
-e QDB_CAIRO_SQL_PARALLEL_FILTER_ENABLED=$sql_parallel \
-e QDB_CAIRO_SQL_PARALLEL_GROUPBY_ENABLED=$sql_parallel \
-e QDB_CAIRO_SQL_PARALLEL_WINDOW_JOIN_ENABLED=$sql_parallel \
-e QDB_CAIRO_SQL_PARALLEL_READ_PARQUET_ENABLED=$sql_parallel \
"$image" >/dev/null

exec_sql() { curl -sf -G "http://$LISTEN_HOST:$http_port/exec" --data-urlencode "query=$1"; }
for _ in $(seq 1 60); do
exec_sql "SELECT 1" >/dev/null 2>&1 && break; sleep 1
done
exec_sql "SELECT 1" >/dev/null || { echo "the server did not start" >&2; docker logs "$name" >&2; exit 1; }

group="/sys/fs/cgroup/system.slice/docker-$(docker inspect -f '{{.Id}}' "$name").scope"
[ -d "$group" ] || { echo "no cgroup at $group (is docker on the systemd cgroup driver?)" >&2; exit 1; }

siblings() {
for core in $(expand_cores "$cores"); do
printf '%s:%s ' "$core" "$(cat "/sys/devices/system/cpu/cpu$core/topology/thread_siblings_list")"
done
}
{ echo "image $image"
echo "image_id $(docker inspect -f '{{.Image}}' "$name")"
echo "version $(exec_sql "SELECT build()" | sed -n 's/.*"dataset":\[\["\([^"]*\)"\]\].*/\1/p')"
echo "parallel_sql $parallel"
echo "memory_limit ${MEMORY_LIMIT:-none}"
echo "cpuset $cores mems $numa"
echo "thread_siblings $(siblings)"
echo "cpu_model $(lscpu | sed -n 's/^Model name: *//p')"
echo "cgroup $group"
echo "kernel $(uname -r)"; } > "$data_dir/versions.txt"
cat "$data_dir/versions.txt"
83 changes: 83 additions & 0 deletions scripts/questdb_variants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/usr/bin/env python3
"""Add the QuestDB variants to a benchmark-external run directory.

scripts/questdb_variants.py <run-directory>

For each workload in <run-directory>/workloads/, writes
plans/<variant>/<workload>.plan.json, a file naming the variant that engine
`questdb` builds its SQL from (`{"questdb_variant": "native"}`), or
<workload>.no-plan.json when the variant's SQL would be the same as
questdb.native's, so identical SQL is not run twice:

questdb.native every query at query time, exact
questdb.materialized-views a materialized view per query, quantiles at query time;
no plan when every query is a quantile
questdb.approximate approx_percentile for quantiles; no plan without a quantile

Example: scripts/questdb_variants.py /data/run-1
"""
import json
import pathlib
import re
import sys

VARIANTS = {
# name: (questdb_variant, substitutions_allowed)
"questdb.native": ("native", False),
"questdb.materialized-views": ("materialized-views", True),
"questdb.approximate": ("approximate", True),
}

QUANTILE = re.compile(r"\bquantile_over_time\s*\(")


def promql_texts(workload):
"""The PromQL text of each query, e.g. ["quantile_over_time(0.99, latency[1m])"]."""
texts = []
for query in workload["queries"]:
promql = [t["text"] for t in query["texts"] if t["language"] == "PromQl"]
texts.append(promql[0] if promql else "")
return texts


def no_plan_reason(variant, texts):
"""Why `variant` has no plan for a workload of `texts`, or None."""
quantiles = [bool(QUANTILE.search(text)) for text in texts]
if variant == "questdb.approximate" and not any(quantiles):
return "no quantile query: its SQL equals questdb.native's"
if variant == "questdb.materialized-views" and all(quantiles):
return "only quantile queries, which read the raw table: its SQL equals questdb.native's"
return None


def write_variants(run):
run = pathlib.Path(run)
workloads = sorted((run / "workloads").glob("*.json"))
if not workloads:
raise SystemExit(f"{run}/workloads holds no workload")
for variant, (name, substitutions) in VARIANTS.items():
directory = run / "plans" / variant
if directory.exists():
raise SystemExit(f"{directory} exists; runs are never overwritten")
for variant, (name, substitutions) in VARIANTS.items():
directory = run / "plans" / variant
directory.mkdir(parents=True)
(directory / "variant.json").write_text(
json.dumps({"substitutions_allowed": substitutions}) + "\n")
for path in workloads:
texts = promql_texts(json.loads(path.read_text()))
reason = no_plan_reason(variant, texts)
if reason is None:
(directory / f"{path.stem}.plan.json").write_text(
json.dumps({"questdb_variant": name}) + "\n")
print(f"{path.stem} {variant}: plan")
else:
(directory / f"{path.stem}.no-plan.json").write_text(
json.dumps({"reason": reason}) + "\n")
print(f"{path.stem} {variant}: no plan ({reason})")


if __name__ == "__main__":
if len(sys.argv) != 2:
raise SystemExit(__doc__)
write_variants(sys.argv[1])
44 changes: 44 additions & 0 deletions scripts/test_questdb_variants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests of questdb_variants.py over the showcase suite: python3 -m unittest scripts/test_questdb_variants.py"""
import json
import pathlib
import shutil
import sys
import tempfile
import unittest

sys.path.insert(0, str(pathlib.Path(__file__).parent))
import questdb_variants # noqa: E402

SUITE = pathlib.Path(__file__).parent.parent / "suites" / "showcase-1m"


class QuestDbVariants(unittest.TestCase):
def test_showcase_cells(self):
with tempfile.TemporaryDirectory() as tmp:
run = pathlib.Path(tmp)
(run / "workloads").mkdir()
for spec in SUITE.glob("*.workload.json"):
shutil.copy(spec, run / "workloads" / spec.name.replace(".workload", ""))
questdb_variants.write_variants(run)
cells = {}
for variant in questdb_variants.VARIANTS:
for path in (run / "plans" / variant).iterdir():
if path.name != "variant.json":
workload, kind = path.name.split(".", 1)
cells[(variant, workload)] = kind
planned = lambda v: sorted(w for (x, w), k in cells.items() if x == v and k == "plan.json")
self.assertEqual(len(planned("questdb.native")), 8)
self.assertEqual(planned("questdb.approximate"),
["avg_quantile", "joint", "quantile", "quantile_rank"])
self.assertEqual(planned("questdb.materialized-views"),
["count", "joint", "max", "sum_over_time", "sum_rate"])
plan = json.loads((run / "plans/questdb.approximate/joint.plan.json").read_text())
self.assertEqual(plan, {"questdb_variant": "approximate"})
native = json.loads((run / "plans/questdb.native/variant.json").read_text())
self.assertEqual(native, {"substitutions_allowed": False})
with self.assertRaises(SystemExit):
questdb_variants.write_variants(run)


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions system-bench/src/engines_external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod kept_process;
pub mod pilotdb;
pub mod plan_file;
pub mod postgresql_command_line;
pub mod questdb;
pub mod questdb_server;
mod restart_command;
pub mod server_cgroup;
pub mod victoriametrics;
Expand Down
Loading