run_flash_bench.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #!/usr/bin/env bash
  2. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. # REQUIRE: benchmark.sh exists in the current directory
  4. # After execution of this script, log files are generated in $output_dir.
  5. # report.txt provides a high level statistics
  6. # This should be run from the parent of the tools directory. The command line is:
  7. # [$env_vars] tools/run_flash_bench.sh [list-of-threads]
  8. #
  9. # This runs a sequence of tests in the following sequence:
  10. # step 1) load - bulkload, compact, fillseq, overwrite
  11. # step 2) read-only for each number of threads
  12. # step 3) read-write for each number of threads
  13. # step 4) merge for each number of threads
  14. #
  15. # The list of threads is optional and when not set is equivalent to "24".
  16. # Were list-of-threads specified as "1 2 4" then the tests in steps 2, 3 and
  17. # 4 above would be repeated for 1, 2 and 4 threads. The tests in step 1 are
  18. # only run for 1 thread.
  19. # Test output is written to $OUTPUT_DIR, currently /tmp/output. The performance
  20. # summary is in $OUTPUT_DIR/report.txt. There is one file in $OUTPUT_DIR per
  21. # test and the tests are listed below.
  22. #
  23. # The environment variables are also optional. The variables are:
  24. #
  25. # NKEYS - number of key/value pairs to load
  26. # BG_MBWRITEPERSEC - write rate limit in MB/second for tests in which
  27. # there is one thread doing writes and stats are
  28. # reported for read threads. "BG" stands for background.
  29. # If this is too large then the non-writer threads can get
  30. # starved. This is used for the "readwhile" tests.
  31. # FG_MBWRITEPERSEC - write rate limit in MB/second for tests like overwrite
  32. # where stats are reported for the write threads.
  33. # NSECONDS - number of seconds for which to run each test in steps 2,
  34. # 3 and 4. There are currently 15 tests in those steps and
  35. # they are repeated for each entry in list-of-threads so
  36. # this variable lets you control the total duration to
  37. # finish the benchmark.
  38. # RANGE_LIMIT - the number of rows to read per range query for tests that
  39. # do range queries.
  40. # VAL_SIZE - the length of the value in the key/value pairs loaded.
  41. # You can estimate the size of the test database from this,
  42. # NKEYS and the compression rate (--compression_ratio) set
  43. # in tools/benchmark.sh
  44. # BLOCK_LENGTH - value for db_bench --block_size
  45. # CACHE_BYTES - the size of the RocksDB block cache in bytes
  46. # DATA_DIR - directory in which to create database files
  47. # LOG_DIR - directory in which to create WAL files, may be the same
  48. # as DATA_DIR
  49. # DO_SETUP - when set to 0 then a backup of the database is copied from
  50. # $DATA_DIR.bak to $DATA_DIR and the load tests from step 1
  51. # The WAL directory is also copied from a backup if
  52. # DATA_DIR != LOG_DIR. This allows tests from steps 2, 3, 4
  53. # to be repeated faster.
  54. # SAVE_SETUP - saves a copy of the database at the end of step 1 to
  55. # $DATA_DIR.bak. When LOG_DIR != DATA_DIR then it is copied
  56. # to $LOG_DIR.bak.
  57. # SKIP_LOW_PRI_TESTS - skip some of the tests which aren't crucial for getting
  58. # actionable benchmarking data (look for keywords "bulkload",
  59. # "sync=1", and "while merging").
  60. #
  61. # Size constants
  62. K=1024
  63. M=$((1024 * K))
  64. G=$((1024 * M))
  65. num_keys=${NKEYS:-$((1 * G))}
  66. # write rate for readwhile... tests
  67. bg_mbwps=${BG_MBWRITEPERSEC:-4}
  68. # write rate for tests other than readwhile, 0 means no limit
  69. fg_mbwps=${FG_MBWRITEPERSEC:-0}
  70. duration=${NSECONDS:-$((60 * 60))}
  71. nps=${RANGE_LIMIT:-10}
  72. vs=${VAL_SIZE:-400}
  73. cs=${CACHE_BYTES:-$(( 1 * G ))}
  74. bs=${BLOCK_LENGTH:-8192}
  75. # If no command line arguments then run for 24 threads.
  76. if [[ $# -eq 0 ]]; then
  77. nthreads=( 24 )
  78. else
  79. nthreads=( "$@" )
  80. fi
  81. for num_thr in "${nthreads[@]}" ; do
  82. echo Will run for $num_thr threads
  83. done
  84. # Update these parameters before execution !!!
  85. db_dir=${DATA_DIR:-"/tmp/rocksdb/"}
  86. wal_dir=${LOG_DIR:-"/tmp/rocksdb/"}
  87. do_setup=${DO_SETUP:-1}
  88. save_setup=${SAVE_SETUP:-0}
  89. # By default we'll run all the tests. Set this to skip a set of tests which
  90. # aren't critical for getting key metrics.
  91. skip_low_pri_tests=${SKIP_LOW_PRI_TESTS:-0}
  92. if [[ $skip_low_pri_tests == 1 ]]; then
  93. echo "Skipping some non-critical tests because SKIP_LOW_PRI_TESTS is set."
  94. fi
  95. output_dir="${TMPDIR:-/tmp}/output"
  96. ARGS="\
  97. OUTPUT_DIR=$output_dir \
  98. NUM_KEYS=$num_keys \
  99. DB_DIR=$db_dir \
  100. WAL_DIR=$wal_dir \
  101. VALUE_SIZE=$vs \
  102. BLOCK_SIZE=$bs \
  103. CACHE_SIZE=$cs"
  104. mkdir -p $output_dir
  105. echo -e "ops/sec\tmb/sec\tSize-GB\tL0_GB\tSum_GB\tW-Amp\tW-MB/s\tusec/op\tp50\tp75\tp99\tp99.9\tp99.99\tUptime\tStall-time\tStall%\tTest" \
  106. > $output_dir/report.txt
  107. # Notes on test sequence:
  108. # step 1) Setup database via sequential fill followed by overwrite to fragment it.
  109. # Done without setting DURATION to make sure that overwrite does $num_keys writes
  110. # step 2) read-only tests for all levels of concurrency requested
  111. # step 3) non read-only tests for all levels of concurrency requested
  112. # step 4) merge tests for all levels of concurrency requested. These must come last.
  113. ###### Setup the database
  114. if [[ $do_setup != 0 ]]; then
  115. echo Doing setup
  116. if [[ $skip_low_pri_tests != 1 ]]; then
  117. # Test 1: bulk load
  118. env $ARGS ./tools/benchmark.sh bulkload
  119. fi
  120. # Test 2a: sequential fill with large values to get peak ingest
  121. # adjust NUM_KEYS given the use of larger values
  122. env $ARGS BLOCK_SIZE=$((1 * M)) VALUE_SIZE=$((32 * K)) NUM_KEYS=$(( num_keys / 64 )) \
  123. ./tools/benchmark.sh fillseq_disable_wal
  124. # Test 2b: sequential fill with the configured value size
  125. env $ARGS ./tools/benchmark.sh fillseq_disable_wal
  126. # Test 2c: same as 2a, but with WAL being enabled.
  127. env $ARGS BLOCK_SIZE=$((1 * M)) VALUE_SIZE=$((32 * K)) NUM_KEYS=$(( num_keys / 64 )) \
  128. ./tools/benchmark.sh fillseq_enable_wal
  129. # Test 2d: same as 2b, but with WAL being enabled.
  130. env $ARGS ./tools/benchmark.sh fillseq_enable_wal
  131. # Test 3: single-threaded overwrite
  132. env $ARGS NUM_THREADS=1 DB_BENCH_NO_SYNC=1 ./tools/benchmark.sh overwrite
  133. else
  134. echo Restoring from backup
  135. rm -rf $db_dir
  136. if [ ! -d ${db_dir}.bak ]; then
  137. echo Database backup does not exist at ${db_dir}.bak
  138. exit -1
  139. fi
  140. echo Restore database from ${db_dir}.bak
  141. cp -p -r ${db_dir}.bak $db_dir
  142. if [[ $db_dir != $wal_dir ]]; then
  143. rm -rf $wal_dir
  144. if [ ! -d ${wal_dir}.bak ]; then
  145. echo WAL backup does not exist at ${wal_dir}.bak
  146. exit -1
  147. fi
  148. echo Restore WAL from ${wal_dir}.bak
  149. cp -p -r ${wal_dir}.bak $wal_dir
  150. fi
  151. fi
  152. if [[ $save_setup != 0 ]]; then
  153. echo Save database to ${db_dir}.bak
  154. cp -p -r $db_dir ${db_dir}.bak
  155. if [[ $db_dir != $wal_dir ]]; then
  156. echo Save WAL to ${wal_dir}.bak
  157. cp -p -r $wal_dir ${wal_dir}.bak
  158. fi
  159. fi
  160. ###### Read-only tests
  161. for num_thr in "${nthreads[@]}" ; do
  162. # Test 4: random read
  163. env $ARGS DURATION=$duration NUM_THREADS=$num_thr ./tools/benchmark.sh readrandom
  164. # Test 5: random range scans
  165. env $ARGS DURATION=$duration NUM_THREADS=$num_thr NUM_NEXTS_PER_SEEK=$nps \
  166. ./tools/benchmark.sh fwdrange
  167. # Test 6: random reverse range scans
  168. env $ARGS DURATION=$duration NUM_THREADS=$num_thr NUM_NEXTS_PER_SEEK=$nps \
  169. ./tools/benchmark.sh revrange
  170. done
  171. ###### Non read-only tests
  172. for num_thr in "${nthreads[@]}" ; do
  173. # Test 7: overwrite with sync=0
  174. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$fg_mbwps \
  175. DB_BENCH_NO_SYNC=1 ./tools/benchmark.sh overwrite
  176. if [[ $skip_low_pri_tests != 1 ]]; then
  177. # Test 8: overwrite with sync=1
  178. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$fg_mbwps \
  179. ./tools/benchmark.sh overwrite
  180. fi
  181. # Test 9: random update with sync=0
  182. env $ARGS DURATION=$duration NUM_THREADS=$num_thr DB_BENCH_NO_SYNC=1 \
  183. ./tools/benchmark.sh updaterandom
  184. if [[ $skip_low_pri_tests != 1 ]]; then
  185. # Test 10: random update with sync=1
  186. env $ARGS DURATION=$duration NUM_THREADS=$num_thr ./tools/benchmark.sh updaterandom
  187. fi
  188. # Test 11: random read while writing
  189. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  190. DB_BENCH_NO_SYNC=1 ./tools/benchmark.sh readwhilewriting
  191. # Test 12: range scan while writing
  192. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  193. DB_BENCH_NO_SYNC=1 NUM_NEXTS_PER_SEEK=$nps ./tools/benchmark.sh fwdrangewhilewriting
  194. # Test 13: reverse range scan while writing
  195. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  196. DB_BENCH_NO_SYNC=1 NUM_NEXTS_PER_SEEK=$nps ./tools/benchmark.sh revrangewhilewriting
  197. done
  198. ###### Merge tests
  199. for num_thr in "${nthreads[@]}" ; do
  200. # Test 14: random merge with sync=0
  201. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$fg_mbwps \
  202. DB_BENCH_NO_SYNC=1 ./tools/benchmark.sh mergerandom
  203. if [[ $skip_low_pri_tests != 1 ]]; then
  204. # Test 15: random merge with sync=1
  205. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$fg_mbwps \
  206. ./tools/benchmark.sh mergerandom
  207. # Test 16: random read while merging
  208. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  209. DB_BENCH_NO_SYNC=1 ./tools/benchmark.sh readwhilemerging
  210. # Test 17: range scan while merging
  211. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  212. DB_BENCH_NO_SYNC=1 NUM_NEXTS_PER_SEEK=$nps ./tools/benchmark.sh fwdrangewhilemerging
  213. # Test 18: reverse range scan while merging
  214. env $ARGS DURATION=$duration NUM_THREADS=$num_thr MB_WRITE_PER_SEC=$bg_mbwps \
  215. DB_BENCH_NO_SYNC=1 NUM_NEXTS_PER_SEEK=$nps ./tools/benchmark.sh revrangewhilemerging
  216. fi
  217. done
  218. ###### Universal compaction tests.
  219. # Use a single thread to reduce the variability in the benchmark.
  220. env $ARGS COMPACTION_TEST=1 NUM_THREADS=1 ./tools/benchmark.sh universal_compaction
  221. if [[ $skip_low_pri_tests != 1 ]]; then
  222. echo bulkload > $output_dir/report2.txt
  223. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  224. grep bulkload $output_dir/report.txt >> $output_dir/report2.txt
  225. fi
  226. echo fillseq_wal_disabled >> $output_dir/report2.txt
  227. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  228. grep fillseq.wal_disabled $output_dir/report.txt >> $output_dir/report2.txt
  229. echo fillseq_wal_enabled >> $output_dir/report2.txt
  230. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  231. grep fillseq.wal_enabled $output_dir/report.txt >> $output_dir/report2.txt
  232. echo overwrite sync=0 >> $output_dir/report2.txt
  233. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  234. grep overwrite $output_dir/report.txt | grep \.s0 >> $output_dir/report2.txt
  235. if [[ $skip_low_pri_tests != 1 ]]; then
  236. echo overwrite sync=1 >> $output_dir/report2.txt
  237. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  238. grep overwrite $output_dir/report.txt | grep \.s1 >> $output_dir/report2.txt
  239. fi
  240. echo updaterandom sync=0 >> $output_dir/report2.txt
  241. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  242. grep updaterandom $output_dir/report.txt | grep \.s0 >> $output_dir/report2.txt
  243. if [[ $skip_low_pri_tests != 1 ]]; then
  244. echo updaterandom sync=1 >> $output_dir/report2.txt
  245. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  246. grep updaterandom $output_dir/report.txt | grep \.s1 >> $output_dir/report2.txt
  247. fi
  248. echo mergerandom sync=0 >> $output_dir/report2.txt
  249. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  250. grep mergerandom $output_dir/report.txt | grep \.s0 >> $output_dir/report2.txt
  251. if [[ $skip_low_pri_tests != 1 ]]; then
  252. echo mergerandom sync=1 >> $output_dir/report2.txt
  253. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  254. grep mergerandom $output_dir/report.txt | grep \.s1 >> $output_dir/report2.txt
  255. fi
  256. echo readrandom >> $output_dir/report2.txt
  257. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  258. grep readrandom $output_dir/report.txt >> $output_dir/report2.txt
  259. echo fwdrange >> $output_dir/report2.txt
  260. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  261. grep fwdrange\.t $output_dir/report.txt >> $output_dir/report2.txt
  262. echo revrange >> $output_dir/report2.txt
  263. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  264. grep revrange\.t $output_dir/report.txt >> $output_dir/report2.txt
  265. echo readwhile >> $output_dir/report2.txt >> $output_dir/report2.txt
  266. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  267. grep readwhilewriting $output_dir/report.txt >> $output_dir/report2.txt
  268. if [[ $skip_low_pri_tests != 1 ]]; then
  269. echo readwhile >> $output_dir/report2.txt
  270. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  271. grep readwhilemerging $output_dir/report.txt >> $output_dir/report2.txt
  272. fi
  273. echo fwdreadwhilewriting >> $output_dir/report2.txt
  274. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  275. grep fwdrangewhilewriting $output_dir/report.txt >> $output_dir/report2.txt
  276. if [[ $skip_low_pri_tests != 1 ]]; then
  277. echo fwdreadwhilemerging >> $output_dir/report2.txt
  278. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  279. grep fwdrangewhilemerg $output_dir/report.txt >> $output_dir/report2.txt
  280. fi
  281. echo revreadwhilewriting >> $output_dir/report2.txt
  282. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  283. grep revrangewhilewriting $output_dir/report.txt >> $output_dir/report2.txt
  284. if [[ $skip_low_pri_tests != 1 ]]; then
  285. echo revreadwhilemerging >> $output_dir/report2.txt
  286. head -1 $output_dir/report.txt >> $output_dir/report2.txt
  287. grep revrangewhilemerg $output_dir/report.txt >> $output_dir/report2.txt
  288. fi
  289. cat $output_dir/report2.txt