db_bench: `--report_file` keeps only the last benchmark when `--benchmarks` lists several
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
./db_bench --db=/tmp/dbb_report/db --benchmarks=fillseq,readrandom \
--num=3000000 --duration=5 \
--report_interval_seconds=1 --report_file=/tmp/dbb_report/a.csvfillseq : 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,561121The report file after the run:
secs_elapsed,interval_qps
1,369869
2,370046
3,372081
4,372909The fillseq rows (~560k qps) were written and then removed; only the
readrandom rows (~370k qps) remain.
2. Control: a single benchmark
./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.csvsecs_elapsed,interval_qps
1,380866
2,384272
3,382099
4,371022With 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..4The final file holds only the four rows of run 3.
Cause
RunBenchmarkconstructs a newReporterAgenton every call ([tools/db_bench_tool.cc#L5298-L5301(https://github.com/facebook/rocksdb/blob/4052fccde9d9533fa9c57749b63ba3cda2c9b134/tools/db_bench_tool.cc#L5298-L5301)). It is called once per benchmark name (L4576), and once per warm-up and per repetition (L5091, L5100).- The
ReporterAgentconstructor opens the file withNewWritableFileand writes the header (L2645-L2650). NewWritableFiletruncates an existing file: on POSIX it opens withO_CREAT | O_TRUNC(env/fs_posix.cc#L393).secs_elapsedis measured from each agent's own start (L2679), so simply appending would repeat the header and restart the time column for every run.
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
- 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
ReporterAgentwrites to that shared file, andsecs_elapsedis measured from a start time shared by the whole invocation. Keeping the file open avoidsReopenWritableFile, which the baseEnvdoes not implement (include/rocksdb/env.h#L277-L281). Single-benchmark output is unchanged. - As 1, plus a
benchmarkcolumn so rows can be attributed to a benchmark. Changes the CSV format. - 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
mainat4052fccde9d9(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).
Source: facebook/rocksdb