#15276·rocksdb

db_bench: `--report_file` keeps only the last benchmark when `--benchmarks` lists several

Author: vinibarbieriCreated Sep 27, 2026Updated Sep 27, 2026

Summary

With --report_interval_seconds > 0, the file given by --report_file is truncated at the start of every benchmark run. When --benchmarks lists more than one benchmark, or uses [Xn] / [Wn], the file ends up containing only the interval rows of the last run; rows written by earlier runs are silently discarded.

Reproduction

Built from main at 4052fccde9d9 with DEBUG_LEVEL=1 make db_bench. --num=3000000 makes fillseq take ~5 s on this machine (--duration does not apply to fillseq); --duration=5 bounds readrandom.

1. Two benchmarks

bash
./db_bench --db=/tmp/dbb_report/db --benchmarks=fillseq,readrandom \
  --num=3000000 --duration=5 \
  --report_interval_seconds=1 --report_file=/tmp/dbb_report/a.csv
fillseq      :       1.786 micros/op 559799 ops/sec 5.359 seconds 3000000 operations;   61.9 MB/s
readrandom   :       2.703 micros/op 369974 ops/sec 5.000 seconds 1849999 operations;   40.9 MB/s (1849999 of 1849999 found)

A copy of the report file taken 3 s into the run (during fillseq):

secs_elapsed,interval_qps
1,557865
2,568720
3,561121

The report file after the run:

secs_elapsed,interval_qps
1,369869
2,370046
3,372081
4,372909

The fillseq rows (~560k qps) were written and then removed; only the readrandom rows (~370k qps) remain.

2. Control: a single benchmark

bash
./db_bench --db=/tmp/dbb_report/db --use_existing_db=1 --benchmarks=readrandom \
  --num=3000000 --duration=5 \
  --report_interval_seconds=1 --report_file=/tmp/dbb_report/b.csv
secs_elapsed,interval_qps
1,380866
2,384272
3,382099
4,371022

With one benchmark the file is complete.

3. Repetitions: readrandom[X3]

Same command as 2 with --benchmarks='readrandom[X3]'. db_bench runs readrandom three times (~5 s each). Polling the report file every 50 ms during the run shows it being truncated back to the header when each run starts:

t= 0.02s  header only           <- run 1 starts
t= 1.03s .. 4.05s  rows 1..4
t= 5.07s  header only           <- run 2 starts, file truncated
t= 6.08s .. 9.06s  rows 1..4
t=10.06s  header only           <- run 3 starts, file truncated
t=11.07s .. 14.05s rows 1..4

The final file holds only the four rows of run 3.

Cause

Benchmarks handled without RunBenchmark (e.g. stats) do not truncate the file, so tools/benchmark.sh, which always passes --benchmarks=<one>,stats, is not affected.

Possible fixes

  1. One file for the whole invocation, same format. Open the report file once, on the first run, keep it open across runs, and write the header once; each run's ReporterAgent writes to that shared file, and secs_elapsed is measured from a start time shared by the whole invocation. Keeping the file open avoids ReopenWritableFile, which the base Env does not implement (include/rocksdb/env.h#L277-L281). Single-benchmark output is unchanged.
  2. As 1, plus a benchmark column so rows can be attributed to a benchmark. Changes the CSV format.
  3. One file per run, e.g. a suffix with the benchmark index/name. No format change, but the file name changes for multi-benchmark runs.

Any of these changes what multi-benchmark invocations write today (only the last run's rows). One open question: should warm-up runs ([Wn]) be written to the report file? Today their rows are always overwritten by the measured runs, which may be the desired outcome; with options 1 and 2 they would appear unless warm-up runs are excluded.

I plan to send a PR implementing option 1 (without warm-up rows unless you prefer otherwise) and am happy to switch to another approach.

Environment

  • RocksDB main at 4052fccde9d9 (version 11.12.0); first observed on v11.8.1, where the relevant code is the same.
  • macOS 26.6.2, arm64 (12 cores), Apple clang 21.0.0, DEBUG_LEVEL=1.

See also #12594 (a different ReporterAgent issue: counter contention with many threads).