benchmark.sh 8.6 KB
Newer Older
1 2 3 4
#!/bin/bash
# REQUIRE: db_bench binary exists in the current directory

if [ $# -ne 1 ]; then
5 6
  echo -n "./benchmark.sh [bulkload/fillseq/overwrite/filluniquerandom/"
  echo    "readrandom/readwhilewriting/updaterandom/mergerandom]"
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  exit 0
fi

# size constants
K=1024
M=$((1024 * K))
G=$((1024 * M))

if [ -z $DB_DIR ]; then
  echo "DB_DIR is not defined"
  exit 0
fi

if [ -z $WAL_DIR ]; then
  echo "WAL_DIR is not defined"
  exit 0
fi

output_dir=${OUTPUT_DIR:-/tmp/}
if [ ! -d $output_dir ]; then
  mkdir -p $output_dir
fi

30 31 32 33 34 35 36 37
# all multithreaded tests run with sync=1 unless
# $DB_BENCH_NO_SYNC is defined
syncval="1"
if [ ! -z $DB_BENCH_NO_SYNC ]; then
  echo "Turning sync off for all multithreaded tests"
  syncval="0";
fi

38 39
num_read_threads=${NUM_READ_THREADS:-16}
writes_per_second=${WRITES_PER_SEC:-$((80 * K))}  # (only for readwhilewriting)
L
Lei Jin 已提交
40
num_nexts_per_seek=${NUM_NEXTS_PER_SEEK:-10}      # (only for rangescanwhilewriting)
L
Lei Jin 已提交
41
cache_size=$((1 * G))
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
duration=${DURATION:-0}

num_keys=${NUM_KEYS:-$((1 * G))}
key_size=20
value_size=800

const_params="
  --db=$DB_DIR \
  --wal_dir=$WAL_DIR \
  \
  --num_levels=6 \
  --key_size=$key_size \
  --value_size=$value_size \
  --block_size=4096 \
  --cache_size=$cache_size \
  --cache_numshardbits=6 \
L
Lei Jin 已提交
58 59
  --compression_type=zlib \
  --min_level_to_compress=2 \
60 61 62 63 64
  --compression_ratio=0.5 \
  \
  --hard_rate_limit=2 \
  --rate_limit_delay_max_milliseconds=1000000 \
  --write_buffer_size=$((128 * M)) \
L
Lei Jin 已提交
65
  --max_write_buffer_number=3 \
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  --target_file_size_base=$((128 * M)) \
  --max_bytes_for_level_base=$((1 * G)) \
  \
  --verify_checksum=1 \
  --delete_obsolete_files_period_micros=$((60 * M)) \
  --max_grandparent_overlap_factor=10 \
  \
  --statistics=1 \
  --stats_per_interval=1 \
  --stats_interval=$((1 * M)) \
  --histogram=1 \
  \
  --memtablerep=skip_list \
  --bloom_bits=10 \
  --open_files=$((20 * K))"

l0_config="
L
Lei Jin 已提交
83 84 85
  --level0_file_num_compaction_trigger=4 \
  --level0_slowdown_writes_trigger=8 \
  --level0_stop_writes_trigger=12"
86 87 88 89 90 91 92 93

if [ $duration -gt 0 ]; then
  const_params="$const_params --duration=$duration"
fi

params_r="$const_params $l0_config --max_background_compactions=4 --max_background_flushes=1"
params_w="$const_params $l0_config --max_background_compactions=16 --max_background_flushes=16"
params_bulkload="$const_params --max_background_compactions=16 --max_background_flushes=16 \
L
Lei Jin 已提交
94 95 96
                 --level0_file_num_compaction_trigger=$((10 * M)) \
                 --level0_slowdown_writes_trigger=$((10 * M)) \
                 --level0_stop_writes_trigger=$((10 * M))"
97 98 99 100 101 102 103

function run_bulkload {
  echo "Bulk loading $num_keys random keys into database..."
  cmd="./db_bench $params_bulkload --benchmarks=fillrandom \
       --use_existing_db=0 \
       --num=$num_keys \
       --disable_auto_compactions=1 \
L
Lei Jin 已提交
104
       --sync=0 \
105
       --disable_data_sync=0 \
106
       --threads=1 2>&1 | tee -a $output_dir/benchmark_bulkload_fillrandom.log"
107 108 109 110 111 112 113
  echo $cmd | tee $output_dir/benchmark_bulkload_fillrandom.log
  eval $cmd
  echo "Compacting..."
  cmd="./db_bench $params_w --benchmarks=compact \
       --use_existing_db=1 \
       --num=$num_keys \
       --disable_auto_compactions=1 \
L
Lei Jin 已提交
114
       --sync=0 \
115
       --disable_data_sync=0 \
116
       --threads=1 2>&1 | tee -a $output_dir/benchmark_bulkload_compact.log"
117 118 119 120 121 122 123 124 125
  echo $cmd | tee $output_dir/benchmark_bulkload_compact.log
  eval $cmd
}

function run_fillseq {
  echo "Loading $num_keys keys sequentially into database..."
  cmd="./db_bench $params_w --benchmarks=fillseq \
       --use_existing_db=0 \
       --num=$num_keys \
126
       --sync=0 \
L
Lei Jin 已提交
127
       --disable_data_sync=0 \
128
       --threads=1 2>&1 | tee -a $output_dir/benchmark_fillseq.log"
129 130 131 132 133 134 135 136 137
  echo $cmd | tee $output_dir/benchmark_fillseq.log
  eval $cmd
}

function run_overwrite {
  echo "Loading $num_keys keys sequentially into database..."
  cmd="./db_bench $params_w --benchmarks=overwrite \
       --use_existing_db=1 \
       --num=$num_keys \
138
       --sync=0 \
L
Lei Jin 已提交
139
       --disable_data_sync=0 \
140
       --threads=1 2>&1 | tee -a $output_dir/benchmark_overwrite.log"
141 142 143 144 145 146 147 148 149
  echo $cmd | tee $output_dir/benchmark_overwrite.log
  eval $cmd
}

function run_filluniquerandom {
  echo "Loading $num_keys unique keys randomly into database..."
  cmd="./db_bench $params_w --benchmarks=filluniquerandom \
       --use_existing_db=0 \
       --num=$num_keys \
150
       --sync=0 \
L
Lei Jin 已提交
151
       --disable_data_sync=0 \
152
       --threads=1 2>&1 | tee -a $output_dir/benchmark_filluniquerandom.log"
153 154 155 156 157 158 159 160 161 162 163
  echo $cmd | tee $output_dir/benchmark_filluniquerandom.log
  eval $cmd
}

function run_readrandom {
  echo "Reading $num_keys random keys from database..."
  cmd="./db_bench $params_r --benchmarks=readrandom \
       --use_existing_db=1 \
       --num=$num_keys \
       --threads=$num_read_threads \
       --disable_auto_compactions=1 \
164
       2>&1 | tee -a $output_dir/benchmark_readrandom.log"
165 166 167 168 169 170 171 172 173
  echo $cmd | tee $output_dir/benchmark_readrandom.log
  eval $cmd
}

function run_readwhilewriting {
  echo "Reading $num_keys random keys from database whiling writing.."
  cmd="./db_bench $params_r --benchmarks=readwhilewriting \
       --use_existing_db=1 \
       --num=$num_keys \
174
       --sync=$syncval \
L
Lei Jin 已提交
175
       --disable_data_sync=0 \
176 177
       --threads=$num_read_threads \
       --writes_per_second=$writes_per_second \
178
       2>&1 | tee -a $output_dir/benchmark_readwhilewriting.log"
179 180 181 182
  echo $cmd | tee $output_dir/benchmark_readwhilewriting.log
  eval $cmd
}

L
Lei Jin 已提交
183 184 185 186 187
function run_rangescanwhilewriting {
  echo "Range scan $num_keys random keys from database whiling writing.."
  cmd="./db_bench $params_r --benchmarks=seekrandomwhilewriting \
       --use_existing_db=1 \
       --num=$num_keys \
188
       --sync=$syncval \
L
Lei Jin 已提交
189 190 191 192
       --disable_data_sync=0 \
       --threads=$num_read_threads \
       --writes_per_second=$writes_per_second \
       --seek_nexts=$num_nexts_per_seek \
193
       2>&1 | tee -a $output_dir/benchmark_rangescanwhilewriting.log"
L
Lei Jin 已提交
194 195 196 197
  echo $cmd | tee $output_dir/benchmark_rangescanwhilewriting.log
  eval $cmd
}

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
function run_updaterandom {
  echo "Read/Modify/Write $num_keys random keys (not using merge).."
  cmd="./db_bench $params_w --benchmarks=updaterandom \
       --use_existing_db=0 \
       --num=$num_keys \
       --sync=$syncval \
       --disable_data_sync=0 \
       --threads=$num_read_threads 2>&1 | tee -a $output_dir/benchmark_updaterandom.log"
  echo $cmd | tee $output_dir/benchmark_updaterandom.log
  eval $cmd
}

function run_mergerandom {
  echo "Read/Modify/Write $num_keys random keys (using merge operator).."
  cmd="./db_bench $params_w --benchmarks=mergerandom \
       --use_existing_db=0 \
       --num=$num_keys \
       --sync=$syncval \
       --disable_data_sync=0 \
       --merge_operator=\"put\" \
       --threads=$num_read_threads 2>&1 | tee -a $output_dir/benchmark_mergerandom.log"
  echo $cmd | tee $output_dir/benchmark_mergerandom.log
  eval $cmd
}

223 224 225 226 227 228 229 230 231 232 233
function now() {
  echo `date +"%s"`
}

report="$output_dir/report.txt"

echo "===== Benchmark ====="

# Run!!!
IFS=',' read -a jobs <<< $1
for job in ${jobs[@]}; do
234 235 236 237 238

  if [ $job != debug ]; then
    echo "Start $job at `date`" | tee -a $report
  fi

239 240 241 242 243 244 245 246 247 248 249 250 251
  start=$(now)
  if [ $job = bulkload ]; then
    run_bulkload
  elif [ $job = fillseq ]; then
    run_fillseq
  elif [ $job = overwrite ]; then
    run_overwrite
  elif [ $job = filluniquerandom ]; then
    run_filluniquerandom
  elif [ $job = readrandom ]; then
    run_readrandom
  elif [ $job = readwhilewriting ]; then
    run_readwhilewriting
L
Lei Jin 已提交
252 253
  elif [ $job = rangescanwhilewriting ]; then
    run_rangescanwhilewriting
254 255 256 257
  elif [ $job = updaterandom ]; then
    run_updaterandom
  elif [ $job = mergerandom ]; then
    run_mergerandom
258
  elif [ $job = debug ]; then
259
    num_keys=1000; # debug
260
    echo "Setting num_keys to $num_keys"
261 262 263 264 265 266
  else
    echo "unknown job $job"
    exit
  fi
  end=$(now)

267 268 269 270
  if [ $job != debug ]; then
    echo "Complete $job in $((end-start)) seconds" | tee -a $report
  fi

271 272 273 274 275 276 277
  if [[ $job == readrandom || $job == readwhilewriting \
     || $job == rangescanwhilewriting || $job == updaterandom \
     || $job == mergerandom ]]; then
    lat=$(grep "micros\/op" "$output_dir/benchmark_$job.log" \
        | grep "ops\/sec" | awk '{print $3}')
    qps=$(grep "micros\/op" "$output_dir/benchmark_$job.log" \
        | grep "ops\/sec" | awk '{print $5}')
278 279 280
    line=$(grep "rocksdb.db.get.micros" "$output_dir/benchmark_$job.log")
    p50=$(echo $line | awk '{print $7}')
    p99=$(echo $line | awk '{print $13}')
L
Lei Jin 已提交
281
    print_percentile=$(echo "$p50 != 0 || $p99 != 0" | bc);
282
    if [ "$print_percentile" == "1" ]; then
L
Lei Jin 已提交
283 284
      echo "Read latency p50 = $p50 us, p99 = $p99 us" | tee -a $report
    fi
285
    echo "QPS = $qps ops/sec" | tee -a $report
L
Lei Jin 已提交
286
    echo "Avg Latency = $lat micros/op " | tee -a $report
287 288
  fi
done