diff --git a/benchmarks/README.md b/benchmarks/README.md index 29b0d9750e93b..bf64c81b7479a 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -131,6 +131,25 @@ You might want to adjust the results location to avoid overwriting previous resu Environment configuration that was picked up by datafusion is logged at `info` level. To verify that datafusion picked up your configuration, run the benchmarks with `RUST_LOG=info` or higher. +### Control iterations and timing + +`bench.sh run` runs the `tpch` benchmarks with `benchmark_runner`, which writes results that `bench.sh compare` reads. +For these benchmarks, `bench.sh` forwards the query argument and the following environment variables to `benchmark_runner`. +It passes each option only when its variable is set. + +| Variable | `benchmark_runner` option | Meaning | +| ------------------------------ | --------------------------------- | ------------------------------------------------------------------------------ | +| `[query]` argument of `bench.sh run` | `--query` | Runs one query | +| `SIMULATE_LATENCY=true` | `--simulate-latency` | Serves local files as if they were remote object storage | +| `ITERATIONS` | `--iterations` | Recorded iterations after one discarded warm-up iteration. tpch defaults to 5 | +| `MAX_TIME` | `--max-time` | Runs each query adaptively for up to this many seconds | +| `LOCKSTEP_IN`, `LOCKSTEP_OUT` | `--lockstep-in`, `--lockstep-out` | FIFOs that let an orchestrator run two checkouts in lockstep. Set both or none | + +```shell +ITERATIONS=10 ./bench.sh run tpch +MAX_TIME=30 ./bench.sh run tpch 21 +``` + ## Comparing performance of main and a branch For TPC-H diff --git a/benchmarks/bench.sh b/benchmarks/bench.sh index 7fa553eefe79f..f518201c8a838 100755 --- a/benchmarks/bench.sh +++ b/benchmarks/bench.sh @@ -176,6 +176,10 @@ DATAFUSION_DIR directory to use (default $DATAFUSION_DIR) RESULTS_NAME folder where the benchmark files are stored SIMULATE_LATENCY Serve local files as if they were remote object storage: per-request latency, per-connection bandwidth and paginated LIST (default false) +ITERATIONS Recorded iterations per query (benchmark_runner benchmarks only) +MAX_TIME Seconds to run each query adaptively (benchmark_runner benchmarks only) +LOCKSTEP_IN Lockstep control FIFO (benchmark_runner benchmarks only, needs LOCKSTEP_OUT) +LOCKSTEP_OUT Lockstep report FIFO (benchmark_runner benchmarks only, needs LOCKSTEP_IN) DATAFUSION_* Set the given datafusion configuration " exit 1 @@ -822,6 +826,34 @@ sql_results_file() { echo "${RESULTS_DIR}/criterion/$1.json" } +# Runs a SQL benchmark suite with benchmark_runner in its plain (non-Criterion) +# mode, which writes dfbench-format JSON that `compare` reads. The arguments +# are the suite name and its options. This function forwards QUERY, +# SIMULATE_LATENCY, ITERATIONS, MAX_TIME, LOCKSTEP_IN and LOCKSTEP_OUT, each +# only when it is set, so the runner defaults apply otherwise. +run_benchmark_runner() { + local args=("$@") + if [ -n "${QUERY}" ]; then + args+=(--query "${QUERY}") + fi + if [ "${SIMULATE_LATENCY}" = "true" ]; then + args+=(--simulate-latency) + fi + if [ -n "${ITERATIONS}" ]; then + args+=(--iterations "${ITERATIONS}") + fi + if [ -n "${MAX_TIME}" ]; then + args+=(--max-time "${MAX_TIME}") + fi + if [ -n "${LOCKSTEP_IN}" ]; then + args+=(--lockstep-in "${LOCKSTEP_IN}") + fi + if [ -n "${LOCKSTEP_OUT}" ]; then + args+=(--lockstep-out "${LOCKSTEP_OUT}") + fi + debug_run $CARGO_COMMAND --bin benchmark_runner -- "${args[@]}" +} + # Runs the tpch benchmark run_tpch() { SCALE_FACTOR=$1 @@ -830,16 +862,18 @@ run_tpch() { exit 1 fi FORMAT=$2 + # The parquet run keeps the dfbench file name so that `compare` matches + # results from older checkouts. + if [ "$FORMAT" = "parquet" ]; then + RESULTS_FILE="${RESULTS_DIR}/tpch_sf${SCALE_FACTOR}.json" + else + RESULTS_FILE="${RESULTS_DIR}/tpch_${FORMAT}_sf${SCALE_FACTOR}.json" + fi + echo "RESULTS_FILE: ${RESULTS_FILE}" echo "Running tpch benchmark..." - - debug_run env BENCH_NAME=tpch \ - BENCH_RESULTS_FILE="$(sql_results_file tpch_sf${SCALE_FACTOR}_${FORMAT})" \ - BENCH_SIZE="${SCALE_FACTOR}" \ - DATA_DIR="${DATA_DIR}" \ - TPCH_FILE_TYPE="${FORMAT}" \ - SIMULATE_LATENCY="${SIMULATE_LATENCY}" \ - ${QUERY:+BENCH_QUERY="${QUERY}"} \ - bash -c "$SQL_CARGO_COMMAND" + # dfbench ran tpch 5 times. Keep that default so the port does not change the measurement. + ITERATIONS="${ITERATIONS:-5}" run_benchmark_runner tpch --format "${FORMAT}" --scale-factor "${SCALE_FACTOR}" \ + --path "${DATA_DIR}" -o "${RESULTS_FILE}" } # Synthesizes two parquet datasets used to measure per-file metadata @@ -1040,16 +1074,11 @@ run_tpch_mem() { echo "Internal error: Scale factor not specified" exit 1 fi + RESULTS_FILE="${RESULTS_DIR}/tpch_mem_sf${SCALE_FACTOR}.json" + echo "RESULTS_FILE: ${RESULTS_FILE}" echo "Running tpch_mem benchmark..." - - debug_run env BENCH_NAME=tpch \ - BENCH_RESULTS_FILE="$(sql_results_file tpch_mem_sf${SCALE_FACTOR})" \ - BENCH_SIZE="${SCALE_FACTOR}" \ - DATA_DIR="${DATA_DIR}" \ - TPCH_FILE_TYPE="mem" \ - SIMULATE_LATENCY="${SIMULATE_LATENCY}" \ - ${QUERY:+BENCH_QUERY="${QUERY}"} \ - bash -c "$SQL_CARGO_COMMAND" + ITERATIONS="${ITERATIONS:-5}" run_benchmark_runner tpch --format mem --scale-factor "${SCALE_FACTOR}" \ + --path "${DATA_DIR}" -o "${RESULTS_FILE}" } # Runs the tpcds benchmark