TPC-H benchmark¶
The lance-context-tpch crate (a workspace tool, not published) generates
TPC-H data as Lance tables, runs the 22 TPC-H queries through the SQL REST
API, checks their results and records every run. Build it with the server:
Generating a fixture¶
writes the eight tables under <data-dir>/tpch/sf<scale factor>/ (or
--location) and registers them in the data directory's generic store
registry, where a server started on --data-dir /data with SQL enabled
resolves lineitem, orders, ... unqualified. A server already running on
the directory sees them at once. Registering replaces entries of the same
names: one TPC-H fixture per data directory is visible at a time.
- Rows come from
tpchgen4.0.0 (pinned), a Rust port of TPC-Hdbgenwhose output is identical todbgen's. Generation is deterministic: the same version and scale factor always produce the same rows. - Types follow the specification: identifiers
Int64, integersInt32, decimalsDecimal128(15, 2), datesDate32, textUtf8, no NULLs. - Layout: each table is generated in parts of
--rows-per-fragmentrows (default 1,048,576), in parallel (--concurrency); every part is one fragment, in part order, soordersandlineitemstay ordered by order key. All parts are committed together: version 1 creates the empty table and version 2 holds every row.--data-storage-versionpicks the Lance file format; compression is Lance's default and no index is built. - Object storage:
--data-dirand--locationmay be URIs;--storage-option key=valuepasses credentials and endpoints.
The manifest records the generator and its version, the scale factor, the layout (rows per fragment, file format version, order, compression, indexes), and for each table its URI, committed version, rows, fragments, stored bytes per column and generation time. Runs pin every query to the manifest's versions.
Running the queries¶
Start one or more servers on the data directory (SQL_ENABLED=true, and
SQL_POOL for a query pool; see SQL queries), then:
lance-context-tpch run --manifest sf1.json \
--endpoint http://node-0:3000 --endpoint http://node-1:3000 \
--modes single,auto,streaming --verify official \
--warmups 1 --iterations 5 --out samples.jsonl --summary summary.json
Modes run one after another. Each query runs --warmups times unmeasured,
then --iterations times; --streams N runs N query streams at once (each
starting at a different query) instead of one query at a time. Queries go to
the endpoints in turn, so each node owns some of them. A run fails when any
measured run fails or returns wrong results; failures (errors, deadlines,
wrong results) are recorded like every other run and never dropped.
samples.jsonl has one line per run, warm-ups included:
| Field | Meaning |
|---|---|
label, mode, query, stream, iteration, warmup, started_at |
Which run this is. |
endpoint, query_id, owner, execution |
Where it ran: the receiving node, the owner, and the routing decision (backend, reason, estimate, distribution). |
bindings, estimate |
The table versions it read and the planner's estimate. |
submit_ms |
The submission round trip: parsing, binding, planning and admission. |
first_rows_ms |
From submission to the first rows received. |
total_ms |
From submission to the final NDJSON record: the REST end-to-end time. |
row_count, result_bytes |
Rows returned and NDJSON bytes received. |
stats |
The server's statistics: planning, queueing, first-batch and execution times, rows, batches and bytes produced, distributed tasks (remote ones too), shuffle bytes and per-stage rows (task skew). |
error, verified, mismatch |
The failure, or the verification result. |
The summary has, per mode and query, the runs, failures, wrong results,
error codes and backends, and the median, quartiles and range of the
end-to-end, submission, first-rows, planning, queueing, execution and
first-batch times, shuffle bytes, and distributed and remote tasks; per
mode, the failed queries and the sum of the 22 median end-to-end times,
which is only defined when every query succeeded. The printed table shows
the median tasks as tasks/remote: a streaming run whose queries show
0/0 was planned as one task per stage and ran on its owner alone, as
small scale factors are.
lance-context-tpch summarize samples.jsonl ... recomputes it from samples
files.
Correctness¶
--verify checks every run, warm-ups included, against:
official: the official TPC-H answers at scale factor 1, from the TPC-H tools (bundled withtpchgen), with the two corrections below;answers:<dir>: answer filesq<N>.outorq<N>.csv(q1.out,q01.csv, ...),|-separated with a header line, at the fixture's scale factor: for instance DuckDB's published answers for scale factors 0.01, 0.1, 1, 10 and 100, or another engine's results;mode:<mode>: the first run of the first mode.
Columns are compared by position. Row counts must be equal; rows must come
in the expected order, except that rows equal in all the ORDER BY columns
may come in any order among themselves. Text, dates and integers must be
equal. Two decimals must agree within one unit of the last digit of the less
precise one (0.01 against the official answers, which print two decimals),
or exactly when it is an integer, in exact decimal arithmetic;
floating-point results may also differ by one part in 10⁹. These rules are
stricter than TPC-H's own (±1% for averages and ratios, ±100 for sums).
The official answers bundled with tpchgen 4.0.0 agree with DuckDB's
published answers in every value but two, which official corrects:
- Q11: the bundled copy cuts
ps_partkeyto the first four characters of the key right-aligned to six (1297for 129760); the TPC-H tools' answer file has the full keys. Results' keys are cut the same way before they are compared, soanswers:with full keys is the stronger check. - Q17: the official answer, 348406.02, is 0.034 below the exact value: the qualifying extended prices sum to 2438842.38, and 2438842.38 / 7 = 348406.0542857…, DuckDB's answer too. TPC-H's tolerances accept both; these rules expect 348406.05.
Queries¶
lance-context-tpch query N prints a query. Each is the specification's
template with the validation parameters (the parameters of the official
answers) and these equivalent adaptations:
- row-count directives as
LIMIT: Q2 100, Q3 10, Q10 20, Q18 100, Q21 100 rows; - Q1's
interval '90' day (3)writteninterval '90' day(DataFusion does not parse the precision qualifier, which does not change the value); - Q15's view as a common table expression (TPC-H's approved variant; the engine runs no DDL);
- no trailing semicolons.
Q11's FRACTION is 0.0001 / SF (clause 2.4.11.3), the only parameter that
depends on the scale factor. It is written with ten decimals as qgen
writes it: 0.0001000000 at scale factor 1 (the validation value),
0.0000100000 at 10. Runs take the scale factor from the manifest;
lance-context-tpch query 11 --scale-factor 10 prints the query at 10.
Measuring¶
- Cold and warm. Warm-up runs fill the nodes' caches. A cold run is the first run after the servers start; the tool does not drop the operating system's page cache, so on local disks a cold run still reads cached files unless the cache is dropped between runs.
- Local processes are not nodes. A pool of processes on one host shares
its CPUs, memory, disk and network: it tests distribution, not multi-node
performance. Record each node's resources with every result.
scripts/benchmarks/tpch/local_pool.pystarts such a pool, runs a command against it and writesnodes.json: each process's CPU seconds and peak resident memory, and the CPUs and memory the host allows (the cgroup CPU quota and memory limit, which a container may set far below the machine's). - Resources per query. While the command runs,
local_pool.pysamples every node twice a second (--resource-interval) intoresources.jsonl: its CPU seconds, resident memory and the bytes it read from and wrote to storage, with the cgroup's CPU seconds and memory.query_resources.py RUNreads them with the run's samples and gives every query run each node's CPU seconds and the cores they kept busy, the bytes read from storage (page-cache hits are not counted, so it tells a warm run from one that read its data from disk), the bytes written (spill files), the largest resident memory, and the CPU that other processes in the cgroup used meanwhile; it lists the runs that took 1.5 times their query's median or more with those numbers, which tells a stalled run (few busy cores), a cold one (bytes read) and a contended one (other processes' CPU) apart. - Concurrency.
--streams 1measures queries in isolation;--streams Nmeasures them under load.
Calibrating routing¶
auto compares each query's estimated time on a reference node with its
thresholds (see Running SQL). Every query's metadata
reports where that estimate goes, execution.estimate.breakdown (seconds
of scan, compute, serial work, spill, exchange, stages and output), next to
the measured stats.execution_ms, so runs measure how far the reference
is from the nodes that ran them:
lance-context-tpch calibrate runs/sf100/samples.jsonl \
--profile profile.json --report calibration.json
calibrate takes the median measured execution time of every query in every
run and mode (successful, verified, measured runs only) and fits one
multiplier per part of the estimate, so that the scaled parts add up to the
measured times: it minimizes the squared logarithms of predicted over
measured time, with a pull of each multiplier toward 1 (--ridge, 0.1 by
default) that keeps parts few queries exercise near the reference.
Exchanges and stage overheads are fitted separately for streaming (network,
starting stages) and staged execution (intermediate storage, committing
stages), from runs in those modes. It prints the multipliers, how well the
runs' own estimates, the fitted ones, and fits that leave each query out
predict the measured times (the median and largest factor between predicted
and measured time, and the share within a factor of two), and every
query's times.
The profile is the reference node with each throughput divided by its
part's multiplier, each stage overhead multiplied by its own, and the cores
scaled by the serial multiplier over the compute one (how much slower one
core is than all of them); operator weights keep their values, since whole
query times cannot tell operators apart. SQL_COST_PROFILE=profile.json
makes nodes estimate with it. Pass the profile the runs used as --base when
they did not use the default. Calibrate on the hardware and storage the
nodes use, with the queries they run: a profile fitted to local disks
overestimates object storage throughput.
A multiplier also absorbs the estimates' own errors in its part. Far below 1 for a part that measured runs rarely do, such as spill, it says that the estimates expect more of that work than runs do (here, operator state above what the queries held), not that the hardware does it that fast; the held-out accuracy is the measure of how well the profile predicts queries it was not fitted to.