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
95 changes: 95 additions & 0 deletions docs/influxdb3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# InfluxDB 3 as a periodic-query system

`approxbench benchmark-external run --engine influxdb3` runs the periodic suites (`suites/showcase-1m`, `suites/showcase-1h`) on an InfluxDB 3 Core server, used the way an InfluxDB user would run those queries.
The adapter is [influxdb3_server](../system-bench/src/engines_external/influxdb3_server.rs); its PromQL-to-SQL rules are in [influxdb3_query](../system-bench/src/engines_external/influxdb3_query.rs).

## Version

InfluxDB 3 Core 3.12.3 (revision 51f4ac865b, DataFusion 52.5), image `influxdb@sha256:f8cd424eff20b584ce41b1ee72959261c4d1b700d2a97c0d21ff1b173b9b1b81` (`influxdb:3.12.3-core`), pinned in `scripts/extbench-up-influxdb3.sh`.

Core is the free single-node server. Enterprise needs a license key and adds compaction and clustering, which these queries do not use.
Core holds at most 5 databases, so the engine holds one install at a time: each repetition of a cell writes all the data again into a fresh database, which is deleted before the next.

## Data

One table per metric, one tag per label (`__name__` is the table), one float field `value`.
Samples are written as line protocol with millisecond timestamps to `/api/v3/write_lp`.
A write returns after the server's write-ahead log flush (every 1 s by default), so the rows can be queried when the ingest step ends.
Queries are SQL sent to `/api/v3/query_sql`, answered as CSV.

## Variants

`scripts/influxdb3-variants.sh <run-directory>` adds three variants to a run directory.
They have no plan files, and run only when `--variant` names them:

| Variant | How each query runs | Exact |
|---|---|---|
| `influxdb3.native` | SQL over the raw rows at query time | yes |
| `influxdb3.downsampled` | the processing engine writes a downsampled table per query at ingest, and the query reads it; a quantile runs as in native | yes |
| `influxdb3.approximate` | quantiles with `approx_percentile_cont` (t-digest, 100 centroids) at query time; the other queries run as in native | quantiles no (recorded as substitutions) |

A downsampled or approximate cell in which every query would run as in native is refused (`NotRun`), since it would repeat the native cell:

| Workload | native | downsampled | approximate |
|---|---|---|---|
| sum_over_time, count, max, sum_rate | runs | runs | refused: no approximate function |
| quantile, quantile_rank, avg_quantile | runs | refused: no exact downsample | runs |
| joint | runs | q4 and q5 downsampled, q1 to q3 native | q1 to q3 approximate, q4 and q5 native |

### Queries

The adapter translates each query's PromQL text: `[sum|count|min|max|avg [by (labels)]] (f(m[w]))`, with `f` one of `sum_over_time`, `count_over_time`, `min_over_time`, `max_over_time`, `avg_over_time`, `quantile_over_time(φ, …)`, `rate` and `increase`.
Any other text is refused at install.
A query at `T` reads `time > T − w AND time <= T`, as PromQL's range `(T − w, T]`.

- `quantile_over_time(φ)` is `percentile_cont(φ) WITHIN GROUP (ORDER BY value)` per series: rank φ·(n − 1) with linear interpolation, as PromQL, except that InfluxDB rounds the interpolation fraction to 6 decimals (the 0.99 quantile of 1..60 is 59.409999, not 59.41). The answer is off by at most 10⁻⁶ of the gap between the two neighbouring values.
- `rate` and `increase` are Prometheus `extrapolatedRate` written in SQL: each step where the counter goes down adds the new value, then the increase is extrapolated to the range's ends (the 1.1 × average-gap threshold and the clamp at zero), and divided by the range for a rate. These are the same rules as ClickHouse's query-time rate.
- `sum by (job)` of `sum_over_time` or `count_over_time` is one grouped aggregate over the rows; other aggregations over per-series values are nested queries.

### Downsampling

InfluxDB 3 has no materialized views or continuous queries. Its documented way to precompute is the processing engine: a Python plugin, usually behind a scheduled trigger (`every:10s`), queries the last interval and writes aggregates into another table.
A scheduled trigger runs on wall-clock time, and the harness replays data time faster than that.
So the adapter installs the plugin ([influxdb3_downsample.py](../system-bench/src/engines_external/influxdb3_downsample.py)) behind a request trigger, and calls it after each chunk is written, with the SQL that downsamples that chunk.
The plugin's work is therefore measured as ingest work.

Buckets are `gcd(window, evaluation interval)` wide, right-closed, and stored at their end time:

- `sum`, `count`, `min`, `max` over time: one row per bucket and series, or per bucket and group when the outer aggregation can read rows directly (`sum` of sums or counts, `max` of maxima, `min` of minima). `avg_over_time` stores sum and count.
- `rate` and `increase`: per bucket and series, the sample count, first and last time and value, and the increase inside the bucket. The query adds the step between adjacent buckets, with the same rule for a counter that goes down, then extrapolates as at query time.
- `quantile_over_time`: no exact downsample. A quantile cannot be combined from per-bucket values, and InfluxDB has no mergeable quantile state.

The last value cache (at most 10 newest values per series) and the distinct value cache (distinct tag values) do not answer aggregates over a window, so no variant uses them.

### Approximate functions

DataFusion's `approx_percentile_cont` (t-digest) is the only approximate function that fits these suites. `approx_distinct` (HyperLogLog) exists, but no suite query counts distinct values.

## Where InfluxDB differs from the truth

- Exact quantiles differ by at most 10⁻⁶ of the gap between the two neighbouring values (`percentile_cont` rounds its interpolation fraction to 6 decimals).
- `approx_percentile_cont` does not interpolate as PromQL. On 60 values per series it answered within two ranks of the exact quantile in the conformance tests (the 0.99 quantile of 1..60: 59.9 instead of 59.41).
- Every other shape is exact, except in the last bits of a floating-point sum (summation order).
- Line protocol cannot carry NaN or infinite values: a chunk with one fails.
- A label named `time` or `value` collides with a column of the table: refused.
- Timestamps must be after 0.

## Measurement

- CPU and memory: the container's cgroup (`--server-cgroup-directory`, `--server-ssh-host`).
- Query wall time per request is recorded; InfluxDB reports no CPU per query.
- An ingest step's wall time is mostly the wait for the write-ahead log flush (1 s by default): a write is acknowledged after the flush. A downsampled arm waits twice per chunk, for its raw rows and for the plugin's rows. This is idle time, not CPU.
- Stored bytes: the database's Parquet files (`system.parquet_files`). The server writes Parquet only when it snapshots its write-ahead log (by default every 600 flushes, about 10 minutes of wall-clock writing). A replay of the suites is shorter than that, so the rows stay in the write-ahead log files and in memory, and the stored bytes are 0. The server's memory (cgroup) is the number to compare; the run commands also record the size of the data directory after each run.

## Commands

```sh
LISTEN_HOST=10.0.0.2 scripts/extbench-up-influxdb3.sh up /data/influxdb3 2,4,6,8 0 18181 # prints the cgroup
scripts/influxdb3-variants.sh <run-directory>
approxbench benchmark-external run --run-directory <run-directory> --engine influxdb3 \
--variant influxdb3.native --variant influxdb3.downsampled --variant influxdb3.approximate \
--influxdb3-url http://10.0.0.2:18181 --server-cgroup-directory <cgroup> --server-ssh-host 10.0.0.2
scripts/extbench-up-influxdb3.sh down /data/influxdb3
```

Conformance tests against a real server: `AQPBM_INFLUXDB3_URL=http://10.0.0.2:18181 cargo test -p system-bench --test influxdb3_conformance -- --ignored --test-threads 1`.
1 change: 1 addition & 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 | | |
| `influxdb3` ([details](./influxdb3.md)) | yes | | |
| `asapquery-backend` | yes | | |
| `asapquery-precompute-engine` | | | yes |
| `fake` (for tests) | yes | | |
Expand Down
113 changes: 113 additions & 0 deletions scripts/extbench-up-influxdb3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash
# Start (or stop) an InfluxDB 3 Core server for
# `approxbench benchmark-external run --engine influxdb3` 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-influxdb3.sh up <data-dir> <cores> <numa-node> <http-port> [<name>]
# scripts/extbench-up-influxdb3.sh down <data-dir> [<name>]
#
# Example: LISTEN_HOST=10.0.0.2 scripts/extbench-up-influxdb3.sh up /data/run-1/influxdb3 2,22 0 18181
#
# 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 runs without auth
# IMAGE the image, pinned by digest (default: InfluxDB 3 Core
# 3.12.3 below)
# MEMORY_LIMIT a docker --memory limit, e.g. 32g (default: none)
#
# 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. The server keeps
# its default settings (WAL flush every 1 s, Parquet files of 10 min, file
# cache, query memory pool), with a local file object store, and the
# processing engine's plugin directory holding the adapter's downsampling
# plugin. Telemetry upload is off.
set -euo pipefail

marker=.extbench-data-dir
# influxdb:3.12.3-core, InfluxDB 3 Core 3.12.3 (revision 51f4ac865b).
default_image=influxdb@sha256:f8cd424eff20b584ce41b1ee72959261c4d1b700d2a97c0d21ff1b173b9b1b81
plugin_source=$(cd "$(dirname "$0")/.." && pwd)/system-bench/src/engines_external/influxdb3_downsample.py
plugin_file=sketch_bench_downsample.py

# 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
}

if [ "${1:-}" = check-listen-host ]; then
private_address "${2:?address}" || { echo "refused: ${2} is not a private address" >&2; exit 1; }
exit 0
fi

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

if [ "$action" = down ]; then
name=${3:-extbench-influxdb3}
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 node}; http_port=${5:?http port}
name=${6:-extbench-influxdb3}
image=${IMAGE:-$default_image}
: "${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; }
[ -f "$plugin_source" ] || { echo "no plugin at $plugin_source" >&2; exit 1; }

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/data" "$data_dir/plugins"; touch "$data_dir/$marker"
cp "$plugin_source" "$data_dir/plugins/$plugin_file"

memory=(); [ -n "${MEMORY_LIMIT:-}" ] && memory=(--memory "$MEMORY_LIMIT")
docker rm -f "$name" >/dev/null 2>&1 || true
docker run -d --name "$name" --network host \
--cpuset-cpus "$cores" --cpuset-mems "$numa" "${memory[@]}" --user "$(id -u):$(id -g)" \
-v "$data_dir/data:/var/lib/influxdb3/data" -v "$data_dir/plugins:/var/lib/influxdb3/plugins" \
-e HOME=/tmp \
--entrypoint influxdb3 "$image" serve \
--node-id extbench --object-store file --data-dir /var/lib/influxdb3/data \
--plugin-dir /var/lib/influxdb3/plugins --http-bind "$LISTEN_HOST:$http_port" \
--without-auth --disable-telemetry-upload --log-filter warn >/dev/null
for _ in $(seq 1 90); do
curl -sf "http://$LISTEN_HOST:$http_port/health" >/dev/null && break; sleep 1
done
curl -sf "http://$LISTEN_HOST:$http_port/health" >/dev/null || { echo "the server did not start" >&2; docker logs "$name" >&2; exit 1; }

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

siblings() {
for core in ${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 $(curl -sf "http://$LISTEN_HOST:$http_port/ping")"
echo "plugin_sha256 $(sha256sum "$data_dir/plugins/$plugin_file" | cut -d' ' -f1)"
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"
28 changes: 28 additions & 0 deletions scripts/influxdb3-variants.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Add the InfluxDB 3 variants to a benchmark-external run directory (one
# `scripts/plan-suite.sh` made, or any with workloads/): three variants with
# no plan files, which no engine runs unless `--variant` names them.
#
# scripts/influxdb3-variants.sh <run-directory>
#
# Variants (plans/<variant>/variant.json):
# influxdb3.native every query in SQL at query time, exact
# influxdb3.downsampled processing-engine downsampled tables where exact, else as native
# influxdb3.approximate approx_percentile_cont for quantiles (substitutions), else as native
#
# Example: scripts/influxdb3-variants.sh /data/run-1, then
# approxbench benchmark-external run --run-directory /data/run-1 --engine influxdb3 \
# --variant influxdb3.native --influxdb3-url http://10.0.0.2:18181 ...
set -euo pipefail

run=${1:?run directory}
[ -d "$run/workloads" ] || { echo "$run has no workloads/" >&2; exit 1; }
for variant in native downsampled approximate; do
dir="$run/plans/influxdb3.$variant"
[ -e "$dir" ] && { echo "$dir exists; left as it is" >&2; continue; }
mkdir -p "$dir"
substitutions=false; [ "$variant" = approximate ] && substitutions=true
printf '{"substitutions_allowed": %s, "plans": false, "run_by_default": false}\n' "$substitutions" \
> "$dir/variant.json"
echo "influxdb3.$variant"
done
45 changes: 45 additions & 0 deletions system-bench/src/engines_external/influxdb3_downsample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# InfluxDB 3 processing-engine plugin of sketch-bench's InfluxDB 3 adapter
# (`influxdb3.downsampled` arms): runs each downsampling query it is given
# over the database's raw tables and writes the rows into a downsampled table,
# as the downsampling plugins of the InfluxDB 3 docs do from a scheduled
# trigger. The adapter calls it through a request trigger at each data-time
# boundary, after the rows up to that boundary were written.
#
# Request body (JSON):
# {"jobs": [{"sql": "SELECT job, bucket_ms, sum(value) AS v FROM ...",
# "table": "downsampled_q1",
# "keys": ["job"],
# "fields": [["v", false]]}]}
# Each row of `sql` becomes one line of `table`: its `keys` as tags (a null
# key is left out), its `fields` (name, integer?) as fields, at time
# `bucket_ms`. Answers {"tables": {"downsampled_q1": {"rows": 10,
# "tags": ["job"]}}}: the rows written and the tags any row carried.
#
# The writes are buffered and flushed when the call returns, before the
# HTTP answer, so the rows are queryable when the adapter's call ends.
import json


def process_request(influxdb3_local, query_parameters, request_headers, request_body, args=None):
body = json.loads(request_body)
tables = {}
for job in body["jobs"]:
rows = influxdb3_local.query(job["sql"])
written = tables.setdefault(job["table"], {"rows": 0, "tags": []})
for row in rows:
line = LineBuilder(job["table"])
for key in job["keys"]:
value = row.get(key)
if value is not None and value != "":
line.tag(key, str(value))
if key not in written["tags"]:
written["tags"].append(key)
for name, integer in job["fields"]:
if integer:
line.int64_field(name, int(row[name]))
else:
line.float64_field(name, float(row[name]))
line.time_ns(int(row["bucket_ms"]) * 1000000)
influxdb3_local.write(line)
written["rows"] += 1
return {"tables": tables}
Loading