#export TEST_TMPDIR=/mnt
#NUM=40000000
#VSIZE=4000
export TEST_TMPDIR=/tmp/test
#export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1
#export LD_PRELOAD=/usr/lib/libtcmalloc_minimal.so.4
NUM=2000000
VSIZE=4000
# some engines appear to ignore the cache_size and just grab as much RAM as they want
CACHE=536870912
# some engines honor the cache_size, give them more.
CACHE2=17179869184
# 3/4 of the base cache size. tokudb always dies at full size.
CACHE3=8589934592
WRATE=0
STATS=200000
DUR=0
#THR="1 2 4 8 16 32 64"
THR="16"
TIME="numactl -i all /usr/bin/time -f Usr\tSys\t%%\tWall\tRSS\tMajor\tMinor\tVolun\tInvol\tIn\tOut\n%U\t%S\t%P\t%E\t%M\t%F\t%R\t%w\t%c\t%I\t%O"

ENGINES=""
#ENGINES="$ENGINES LevelDB"
LevelDB_cmd="./db_bench"
LevelDB_arg="--cache_size=$CACHE --write_buffer_size=268435456 --open_files=500000 --bloom_bits=10"
#ENGINES="$ENGINES Basho"
Basho_cmd="./db_bench_basho"
Basho_arg="--cache_size=$CACHE2 --write_buffer_size=268435456 --open_files=500000 --bloom_bits=10"
#ENGINES="$ENGINES BDB"
BDB_cmd="./db_bench_bdb"
BDB_arg="--cache_size=$CACHE2"
#ENGINES="$ENGINES Hyper"
Hyper_cmd="./db_bench_hyper"
Hyper_arg="--cache_size=$CACHE --write_buffer_size=268435456 --open_files=500000 --bloom_bits=10"
#ENGINES="$ENGINES LMDB"
LMDB_cmd="./db_bench_mdb"
LMDB_arg="--readahead=0"
#ENGINES="$ENGINES RocksDB"
RocksDB_cmd="./db_bench_rocksdb"
RocksDB_arg="--cache_size=$CACHE --write_buffer_size=268435456"
#ENGINES="$ENGINES RocksDB2"
RocksDB2_cmd="./db_bench.rocks"
RocksDB2_arg="--disable_seek_compaction=1 --mmap_read=0 --statistics=0 --key_size=16 --block_size=4096 --cache_size=$CACHE --bloom_bits=10 --cache_numshardbits=6 --open_files=500000 --compression_type=none --compression_ratio=1 --write_buffer_size=134217728 --target_file_size_base=67108864 --max_write_buffer_number=3 --max_background_compactions=20 --level0_file_num_compaction_trigger=4 --level0_slowdown_writes_trigger=8 --level0_stop_writes_trigger=12 --num_levels=6 --delete_obsolete_files_period_micros=300000000 --min_level_to_compress=2 --max_grandparent_overlap_factor=10 --stats_per_interval=0 --max_bytes_for_level_base=536870912"
ENGINES="$ENGINES TokuDB"
TokuDB_cmd="./db_bench_tokudb"
TokuDB_arg="--cache_size=$CACHE3"
#ENGINES="$ENGINES WiredLSM"
WiredLSM_cmd="./db_bench_wiredtiger"
WiredLSM_arg="--cache_size=$CACHE"
#ENGINES="$ENGINES WiredBtree"
WiredBtree_cmd="./db_bench_wiredtiger --use_lsm=0"
WiredBtree_arg="--cache_size=$CACHE"


for ENG in $ENGINES; do
  rm -r $TEST_TMPDIR/db*
  CMD="\$${ENG}_cmd"
  CMD=`eval echo $CMD`
  ARG="\$${ENG}_arg"
  ARG=`eval echo $ARG`
  echo "ENGINE=$ENG"
  date +%Y/%m/%d-%H:%M:%S
  $TIME $CMD --benchmarks=fillseqbatch --stats_interval=$STATS --num=$NUM --value_size=$VSIZE $ARG
  date +%Y/%m/%d-%H:%M:%S
  for THREADS in $THR; do
    echo THREADS=$THREADS
	$TIME $CMD --benchmarks=readwhilewriting --threads=$THREADS --stats_interval=$STATS --num=$NUM --value_size=$VSIZE --use_existing_db=1 --writes_per_second=$WRATE --duration=$DUR $ARG
    date +%Y/%m/%d-%H:%M:%S
    du $TEST_TMPDIR
  done
done
exit
