Skip to content

Commit add22e3

Browse files
author
Lei Jin
committed
standardize scripts to run RocksDB benchmarks
Summary: Hope these scripts will allow people to run/repro benchmark easily I think it is time to re-run flash benchmarks and report results Please comment if any other benchmark runs are needed Test Plan: ran it Reviewers: yhchiang, igor, sdong Reviewed By: igor Subscribers: dhruba, MarkCallaghan, leveldb Differential Revision: https://reviews.facebook.net/D23139
1 parent dee91c2 commit add22e3

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed

tools/benchmark.sh

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
#!/bin/bash
2+
# REQUIRE: db_bench binary exists in the current directory
3+
4+
if [ $# -ne 1 ]; then
5+
echo "./benchmark.sh [bulkload/fillseq/overwrite/filluniquerandom/readrandom/readwhilewriting]"
6+
exit 0
7+
fi
8+
9+
# size constants
10+
K=1024
11+
M=$((1024 * K))
12+
G=$((1024 * M))
13+
14+
if [ -z $DB_DIR ]; then
15+
echo "DB_DIR is not defined"
16+
exit 0
17+
fi
18+
19+
if [ -z $WAL_DIR ]; then
20+
echo "WAL_DIR is not defined"
21+
exit 0
22+
fi
23+
24+
output_dir=${OUTPUT_DIR:-/tmp/}
25+
if [ ! -d $output_dir ]; then
26+
mkdir -p $output_dir
27+
fi
28+
29+
num_read_threads=${NUM_READ_THREADS:-16}
30+
writes_per_second=${WRITES_PER_SEC:-$((80 * K))} # (only for readwhilewriting)
31+
cache_size=$((16 * G))
32+
duration=${DURATION:-0}
33+
34+
num_keys=${NUM_KEYS:-$((1 * G))}
35+
key_size=20
36+
value_size=800
37+
38+
const_params="
39+
--db=$DB_DIR \
40+
--wal_dir=$WAL_DIR \
41+
\
42+
--num_levels=6 \
43+
--key_size=$key_size \
44+
--value_size=$value_size \
45+
--block_size=4096 \
46+
--cache_size=$cache_size \
47+
--cache_numshardbits=6 \
48+
--compression_type=snappy \
49+
--compression_ratio=0.5 \
50+
\
51+
--hard_rate_limit=2 \
52+
--rate_limit_delay_max_milliseconds=1000000 \
53+
--write_buffer_size=$((128 * M)) \
54+
--max_write_buffer_number=2 \
55+
--target_file_size_base=$((128 * M)) \
56+
--max_bytes_for_level_base=$((1 * G)) \
57+
\
58+
--sync=0 \
59+
--disable_data_sync=1 \
60+
--verify_checksum=1 \
61+
--delete_obsolete_files_period_micros=$((60 * M)) \
62+
--max_grandparent_overlap_factor=10 \
63+
\
64+
--statistics=1 \
65+
--stats_per_interval=1 \
66+
--stats_interval=$((1 * M)) \
67+
--histogram=1 \
68+
\
69+
--memtablerep=skip_list \
70+
--bloom_bits=10 \
71+
--open_files=$((20 * K))"
72+
73+
l0_config="
74+
--level0_file_num_compaction_trigger=8 \
75+
--level0_slowdown_writes_trigger=16 \
76+
--level0_stop_writes_trigger=24"
77+
78+
if [ $duration -gt 0 ]; then
79+
const_params="$const_params --duration=$duration"
80+
fi
81+
82+
params_r="$const_params $l0_config --max_background_compactions=4 --max_background_flushes=1"
83+
params_w="$const_params $l0_config --max_background_compactions=16 --max_background_flushes=16"
84+
params_bulkload="$const_params --max_background_compactions=16 --max_background_flushes=16 \
85+
--level0_file_num_compaction_trigger=$((100 * M)) \
86+
--level0_slowdown_writes_trigger=$((100 * M)) \
87+
--level0_stop_writes_trigger=$((100 * M))"
88+
89+
function run_bulkload {
90+
echo "Bulk loading $num_keys random keys into database..."
91+
cmd="./db_bench $params_bulkload --benchmarks=fillrandom \
92+
--use_existing_db=0 \
93+
--num=$num_keys \
94+
--disable_auto_compactions=1 \
95+
--disable_data_sync=1 \
96+
--threads=1 2>&1 | tee $output_dir/benchmark_bulkload_fillrandom.log"
97+
echo $cmd | tee $output_dir/benchmark_bulkload_fillrandom.log
98+
eval $cmd
99+
echo "Compacting..."
100+
cmd="./db_bench $params_w --benchmarks=compact \
101+
--use_existing_db=1 \
102+
--num=$num_keys \
103+
--disable_auto_compactions=1 \
104+
--disable_data_sync=1 \
105+
--threads=1 2>&1 | tee $output_dir/benchmark_bulkload_compact.log"
106+
echo $cmd | tee $output_dir/benchmark_bulkload_compact.log
107+
eval $cmd
108+
}
109+
110+
function run_fillseq {
111+
echo "Loading $num_keys keys sequentially into database..."
112+
cmd="./db_bench $params_w --benchmarks=fillseq \
113+
--use_existing_db=0 \
114+
--num=$num_keys \
115+
--threads=1 2>&1 | tee $output_dir/benchmark_fillseq.log"
116+
echo $cmd | tee $output_dir/benchmark_fillseq.log
117+
eval $cmd
118+
}
119+
120+
function run_overwrite {
121+
echo "Loading $num_keys keys sequentially into database..."
122+
cmd="./db_bench $params_w --benchmarks=overwrite \
123+
--use_existing_db=1 \
124+
--num=$num_keys \
125+
--threads=1 2>&1 | tee $output_dir/benchmark_overwrite.log"
126+
echo $cmd | tee $output_dir/benchmark_overwrite.log
127+
eval $cmd
128+
}
129+
130+
function run_filluniquerandom {
131+
echo "Loading $num_keys unique keys randomly into database..."
132+
cmd="./db_bench $params_w --benchmarks=filluniquerandom \
133+
--use_existing_db=0 \
134+
--num=$num_keys \
135+
--threads=1 2>&1 | tee $output_dir/benchmark_filluniquerandom.log"
136+
echo $cmd | tee $output_dir/benchmark_filluniquerandom.log
137+
eval $cmd
138+
}
139+
140+
function run_readrandom {
141+
echo "Reading $num_keys random keys from database..."
142+
cmd="./db_bench $params_r --benchmarks=readrandom \
143+
--use_existing_db=1 \
144+
--num=$num_keys \
145+
--threads=$num_read_threads \
146+
--disable_auto_compactions=1 \
147+
2>&1 | tee $output_dir/benchmark_readrandom.log"
148+
echo $cmd | tee $output_dir/benchmark_readrandom.log
149+
eval $cmd
150+
}
151+
152+
function run_readwhilewriting {
153+
echo "Reading $num_keys random keys from database whiling writing.."
154+
cmd="./db_bench $params_r --benchmarks=readwhilewriting \
155+
--use_existing_db=1 \
156+
--num=$num_keys \
157+
--threads=$num_read_threads \
158+
--writes_per_second=$writes_per_second \
159+
2>&1 | tee $output_dir/benchmark_readwhilewriting.log"
160+
echo $cmd | tee $output_dir/benchmark_readwhilewriting.log
161+
eval $cmd
162+
}
163+
164+
function now() {
165+
echo `date +"%s"`
166+
}
167+
168+
report="$output_dir/report.txt"
169+
170+
# print start time
171+
echo "===== Benchmark ====="
172+
173+
# Run!!!
174+
IFS=',' read -a jobs <<< $1
175+
for job in ${jobs[@]}; do
176+
echo "Start $job at `date`" | tee -a $report
177+
start=$(now)
178+
if [ $job = bulkload ]; then
179+
run_bulkload
180+
elif [ $job = fillseq ]; then
181+
run_fillseq
182+
elif [ $job = overwrite ]; then
183+
run_overwrite
184+
elif [ $job = filluniquerandom ]; then
185+
run_filluniquerandom
186+
elif [ $job = readrandom ]; then
187+
run_readrandom
188+
elif [ $job = readwhilewriting ]; then
189+
run_readwhilewriting
190+
else
191+
echo "unknown job $job"
192+
exit
193+
fi
194+
end=$(now)
195+
196+
echo "Complete $job in $((end-start)) seconds" | tee -a $report
197+
if [[ $job = readrandom || $job = readwhilewriting ]]; then
198+
qps=$(grep "micros\/op" "$output_dir/benchmark_$job.log" | grep "ops\/sec" | awk '{print $5}')
199+
line=$(grep "rocksdb.db.get.micros" "$output_dir/benchmark_$job.log")
200+
p50=$(echo $line | awk '{print $7}')
201+
p99=$(echo $line | awk '{print $13}')
202+
echo "Read latency p50 = $p50 us, p99 = $p99 us" | tee -a $report
203+
echo "QPS = $qps ops/sec" | tee -a $report
204+
fi
205+
done

tools/run_flash_bench.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# REQUIRE: benchmark.sh exists in the current directory
3+
# After execution of this script, log files are generated in $output_dir.
4+
# report.txt provides a high level statistics
5+
6+
# Size constants
7+
K=1024
8+
M=$((1024 * K))
9+
G=$((1024 * M))
10+
11+
n=$((1 * G))
12+
wps=$((80 * K))
13+
duration=$((6 * 60 * 60))
14+
num_read_threads=24
15+
16+
# Update these parameters before execution !!!
17+
db_dir="/tmp/rocksdb/"
18+
wal_dir="/tmp/rocksdb/"
19+
output_dir="/tmp/output"
20+
21+
# Test 1: bulk load
22+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
23+
./benchmark.sh bulkload
24+
25+
# Test 2: sequential fill
26+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
27+
./benchmark.sh fillseq
28+
29+
# Test 3: overwrite
30+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
31+
./benchmark.sh overwrite
32+
33+
# Prepare: populate DB with random data
34+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
35+
./benchmark.sh filluniquerandom
36+
37+
# Test 4: random read
38+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
39+
DURATION=$duration NUM_READ_THREADS=$num_read_threads \
40+
./benchmark.sh readrandom
41+
42+
# Test 5: random read while writing
43+
OUTPUT_DIR=$output_dir NUM_KEYS=$n DB_DIR=$db_dir WAL_DIR=$wal_dir \
44+
DURATION=$duration NUM_READ_THREADS=$num_read_threads WRITES_PER_SECOND=$wps \
45+
./benchmark.sh readwhilewriting

0 commit comments

Comments
 (0)